class SmcUtil::FileValidator
Attributes
errors[R]
file[R]
Public Class Methods
new(file)
click to toggle source
# File lib/smcutil/file_validator.rb, line 7 def initialize(file) @file = file end
Public Instance Methods
valid?()
click to toggle source
# File lib/smcutil/file_validator.rb, line 19 def valid? validate! !@errors.any? end
validate!()
click to toggle source
# File lib/smcutil/file_validator.rb, line 11 def validate! @errors = [] validate_regions! validate_headers! validate_signature! end
validate_headers!()
click to toggle source
# File lib/smcutil/file_validator.rb, line 29 def validate_headers! return false unless @file.headers.any? || (@file.headers.count != @file.regions.count) hash_algorithm = nil case @file.headers[0].length when 20 hash_algorithm = OpenSSL::Digest::SHA1 when 32 hash_algorithm = OpenSSL::Digest::SHA256 when 64 hash_algorithm = OpenSSL::Digest::SHA512 else @errors << "ERROR: Digest of header row with length #{@file.headers[0].count} bytes is unsupported. (But pull requests are accepted)" and return end zipped_regions = @file.regions.zip(@file.headers) zipped_regions.each do |region, header| begin hash = hash_algorithm.new hash << region.data if hash.digest == header puts "DEBUG: Validated hash for region #{region}" if SmcUtil::DEBUG else @errors << "Header hash for region #{region} does not match expected" end rescue => ex puts "ERROR: #{ex}" puts ex.backtrace end end end
validate_regions!()
click to toggle source
# File lib/smcutil/file_validator.rb, line 25 def validate_regions! @file.regions.any? end
validate_signature!()
click to toggle source
# File lib/smcutil/file_validator.rb, line 64 def validate_signature! # TODO: Find the RSA 2048 bit key that signs this end