Module: Sigstore::TUF::BaseFile::ClassMethods
- Defined in:
- lib/sigstore/tuf/file.rb
Instance Method Summary collapse
- #validate_hashes(hashes) ⇒ Object
- #validate_length(length) ⇒ Object
- #verify_hashes(data, expected_hashed) ⇒ Object
- #verify_length(data, expected_length) ⇒ Object
Instance Method Details
#validate_hashes(hashes) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/sigstore/tuf/file.rb', line 45 def validate_hashes(hashes) raise ArgumentError, "hashes must be non-empty" if hashes.empty? hashes.each do |algorithm, hash| raise TypeError, "hashes items must be strings" unless algorithm.is_a?(String) && hash.is_a?(String) end end |
#validate_length(length) ⇒ Object
53 54 55 56 57 |
# File 'lib/sigstore/tuf/file.rb', line 53 def validate_length(length) return unless length.negative? raise ArgumentError, "length must be a non-negative integer, got #{length.inspect}" end |
#verify_hashes(data, expected_hashed) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/sigstore/tuf/file.rb', line 27 def verify_hashes(data, expected_hashed) expected_hashed.each do |algorithm, expected_hash| actual_hash = Digest(algorithm.upcase).hexdigest(data) unless actual_hash == expected_hash raise Error::LengthOrHashMismatch, "observed hash #{actual_hash} does not match expected hash #{expected_hash}" end end end |
#verify_length(data, expected_length) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/sigstore/tuf/file.rb', line 37 def verify_length(data, expected_length) actual_length = data.bytesize return if actual_length == expected_length raise Error::LengthOrHashMismatch, "Observed length #{actual_length} does not match expected length #{expected_length}" end |