class Aws::Plugins::GlacierChecksums::Handler

Constants

HASH
TREE_HASH

Public Instance Methods

call(context) click to toggle source
# File lib/aws-sdk-core/plugins/glacier_checksums.rb, line 36
def call(context)
  unless context.http_request.headers[TREE_HASH]
    populate_checksum_headers(context)
  end
  @handler.call(context)
end

Private Instance Methods

compute_checksums(body) { |digest, tree_hash| ... } click to toggle source

Computes two checksums of the body. The tree hash is required by Glacier for operations where you upload a file. The other checksum is required by signature version 4. We compute both here so the sigv4 signer does not need to re-read the body.

# File lib/aws-sdk-core/plugins/glacier_checksums.rb, line 57
def compute_checksums(body, &block)

  tree_hash = TreeHash.new
  digest = OpenSSL::Digest.new('sha256')

  # if the body is empty/EOF, then we should compute the
  # digests of the empty string
  if body.size == 0
    tree_hash.update('')
    digest.update('')
  end

  while chunk = body.read(1024 * 1024) # read 1MB
    tree_hash.update(chunk)
    digest.update(chunk)
  end
  body.rewind

  yield(digest.to_s, tree_hash)

end
populate_checksum_headers(context) click to toggle source
# File lib/aws-sdk-core/plugins/glacier_checksums.rb, line 45
def populate_checksum_headers(context)
  compute_checksums(context.http_request.body) do |hash, tree_hash|
    context.http_request.headers[HASH] = hash
    context.http_request.headers[TREE_HASH] = tree_hash.digest
    context[:tree_hash] = tree_hash
  end
end