class Aws::Plugins::GlacierChecksums::Handler
def call(context)
def call(context) unless context.http_request.headers[TREE_HASH] populate_checksum_headers(context) end @handler.call(context) end
def compute_checksums(body, &block)
checksum is required by signature version 4. We compute both
by Glacier for operations where you upload a file. The other
Computes two checksums of the body. The tree hash is required
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 # Rewind body before performing checksum computation. body.rewind 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
def populate_checksum_headers(context)
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