Sha256: d0c360d690fe06fcceeb7e8caac394252c8e369d2ddb27e979f6d98247fd6a22

Contents?: true

Size: 1.4 KB

Versions: 493

Compression:

Stored size: 1.4 KB

Contents

module Aws
  module S3
    module Encryption
      # @api private
      class IOAuthDecrypter

        # @option options [required, IO#write] :io
        #   An IO-like object that responds to {#write}.
        # @option options [required, Integer] :encrypted_content_length
        #   The number of bytes to decrypt from the `:io` object.
        #   This should be the total size of `:io` minus the length of
        #   the cipher auth tag.
        # @option options [required, OpenSSL::Cipher] :cipher An initialized
        #   cipher that can be used to decrypt the bytes as they are
        #   written to the `:io` object. The cipher should already have
        #   its `#auth_tag` set.
        def initialize(options = {})
          @decrypter = IODecrypter.new(options[:cipher], options[:io])
          @max_bytes = options[:encrypted_content_length]
          @bytes_written = 0
        end

        def write(chunk)
          chunk = truncate_chunk(chunk)
          @bytes_written += chunk.bytesize
          @decrypter.write(chunk)
        end

        def finalize
          @decrypter.finalize
        end

        def io
          @decrypter.io
        end

        private

        def truncate_chunk(chunk)
          if chunk.bytesize + @bytes_written <= @max_bytes
            chunk
          else
            chunk[0..(@max_bytes - @bytes_written - 1)]
          end
        end

      end
    end
  end
end

Version data entries

493 entries across 493 versions & 3 rubygems

Version Path
aws-sdk-resources-2.11.112 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.111 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.110 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.109 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.108 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.107 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.106 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.105 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.104 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.103 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.102 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.101 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.100 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.99 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.98 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.97 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.96 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.95 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.94 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb
aws-sdk-resources-2.11.93 lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb