Sha256: c384dd135dfcc64cf33deba833a3106804ddcf56ae94e0f5de73ad0d0c02dd35

Contents?: true

Size: 2 KB

Versions: 202

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

require 'base64'

module Aws
  module S3
    module Encryption
      # @api private
      class EncryptHandler < Seahorse::Client::Handler

        def call(context)
          envelope, cipher = context[:encryption][:cipher_provider].encryption_cipher
          apply_encryption_envelope(context, envelope, cipher)
          apply_encryption_cipher(context, cipher)
          apply_cse_user_agent(context)
          @handler.call(context)
        end

        private

        def apply_encryption_envelope(context, envelope, cipher)
          context[:encryption][:cipher] = cipher
          if context[:encryption][:envelope_location] == :metadata
            context.params[:metadata] ||= {}
            context.params[:metadata].update(envelope)
          else # :instruction_file
            suffix = context[:encryption][:instruction_file_suffix]
            context.client.put_object(
              bucket: context.params[:bucket],
              key: context.params[:key] + suffix,
              body: Json.dump(envelope)
            )
          end
        end

        def apply_encryption_cipher(context, cipher)
          io = context.params[:body] || ''
          io = StringIO.new(io) if String === io
          context.params[:body] = IOEncrypter.new(cipher, io)
          context.params[:metadata] ||= {}
          context.params[:metadata]['x-amz-unencrypted-content-length'] = io.size
          if context.params.delete(:content_md5)
            warn('Setting content_md5 on client side encrypted objects is deprecated')
          end
          context.http_response.on_headers do
            context.params[:body].close
          end
        end

        def apply_cse_user_agent(context)
          if context.config.user_agent_suffix.nil?
            context.config.user_agent_suffix = EC_USER_AGENT
          elsif !context.config.user_agent_suffix.include? EC_USER_AGENT
            context.config.user_agent_suffix += " #{EC_USER_AGENT}"
          end
        end

      end
    end
  end
end

Version data entries

202 entries across 202 versions & 2 rubygems

Version Path
aws-sdk-s3-1.173.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.172.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.171.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.170.1 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.170.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.169.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.168.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.167.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.166.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.165.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.164.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.163.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.162.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.161.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.160.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.159.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.158.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.157.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.156.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb
aws-sdk-s3-1.155.0 lib/aws-sdk-s3/encryption/encrypt_handler.rb