class Aws::Plugins::ChecksumAlgorithm
@api private
Constants
- CHECKSUM_ALGORITHM_PRIORITIES
priority order of checksum algorithms to validate responses against Remove any algorithms not supported by client (ie, depending on CRT availability)
- CHECKSUM_SIZE
byte size of checksums, used in computing the trailer length
- CHUNK_SIZE
- CLIENT_ALGORITHMS
determine the set of supported client side checksum algorithms CRC32c requires aws-crt (optional sdk dependency) for support
Private Class Methods
calculate_checksum(algorithm, body)
click to toggle source
# File lib/aws-sdk-core/plugins/checksum_algorithm.rb, line 248 def self.calculate_checksum(algorithm, body) digest = ChecksumAlgorithm.digest_for_algorithm(algorithm) if body.respond_to?(:read) ChecksumAlgorithm.update_in_chunks(digest, body) else digest.update(body) end digest.base64digest end
digest_for_algorithm(algorithm)
click to toggle source
# File lib/aws-sdk-core/plugins/checksum_algorithm.rb, line 258 def self.digest_for_algorithm(algorithm) case algorithm when 'CRC32' Digest32.new(Zlib.method(:crc32)) when 'CRC32C' # this will only be used if input algorithm is CRC32C AND client supports it (crt available) Digest32.new(Aws::Crt::Checksums.method(:crc32c)) when 'SHA1' Digest::SHA1.new when 'SHA256' Digest::SHA256.new end end
operation_response_algorithms(context)
click to toggle source
# File lib/aws-sdk-core/plugins/checksum_algorithm.rb, line 79 def self.operation_response_algorithms(context) return unless context.operation.http_checksum context.operation.http_checksum['responseAlgorithms'] end
request_algorithm_selection(context)
click to toggle source
# File lib/aws-sdk-core/plugins/checksum_algorithm.rb, line 65 def self.request_algorithm_selection(context) return unless context.operation.http_checksum input_member = context.operation.http_checksum['requestAlgorithmMember'] context.params[input_member.to_sym]&.upcase if input_member end
request_validation_mode(context)
click to toggle source
# File lib/aws-sdk-core/plugins/checksum_algorithm.rb, line 72 def self.request_validation_mode(context) return unless context.operation.http_checksum input_member = context.operation.http_checksum['requestValidationModeMember'] context.params[input_member.to_sym] if input_member end
trailer_length(algorithm, location_name)
click to toggle source
The trailer size (in bytes) is the overhead + the trailer name + the length of the base64 encoded checksum
# File lib/aws-sdk-core/plugins/checksum_algorithm.rb, line 274 def self.trailer_length(algorithm, location_name) CHECKSUM_SIZE[algorithm] + location_name.size end
update_in_chunks(digest, io)
click to toggle source
# File lib/aws-sdk-core/plugins/checksum_algorithm.rb, line 278 def self.update_in_chunks(digest, io) loop do chunk = io.read(CHUNK_SIZE) break unless chunk digest.update(chunk) end io.rewind end
Public Instance Methods
add_handlers(handlers, _config)
click to toggle source
# File lib/aws-sdk-core/plugins/checksum_algorithm.rb, line 56 def add_handlers(handlers, _config) handlers.add(OptionHandler, step: :initialize) # priority set low to ensure checksum is computed AFTER the request is # built but before it is signed handlers.add(ChecksumHandler, priority: 15, step: :build) end