class Aws::Plugins::ChecksumAlgorithm

@api private

def self.calculate_checksum(algorithm, body)

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

def self.digest_for_algorithm(algorithm)

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

def self.operation_response_algorithms(context)

def self.operation_response_algorithms(context)
  return unless context.operation.http_checksum
  context.operation.http_checksum['responseAlgorithms']
end

def self.request_algorithm_selection(context)

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

def self.request_validation_mode(context)

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

def self.trailer_length(algorithm, location_name)

the length of the base64 encoded checksum
The trailer size (in bytes) is the overhead + the trailer name +
def self.trailer_length(algorithm, location_name)
  CHECKSUM_SIZE[algorithm] + location_name.size
end

def self.update_in_chunks(digest, io)

def self.update_in_chunks(digest, io)
  loop do
    chunk = io.read(CHUNK_SIZE)
    break unless chunk
    digest.update(chunk)
  end
  io.rewind
end

def add_handlers(handlers, _config)

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