Sha256: af4e28eb0bf37e49ec00a41f6512ac3e2e4664986b0051358e37c8ec9e9336e7

Contents?: true

Size: 1.65 KB

Versions: 685

Compression:

Stored size: 1.65 KB

Contents

require 'base64'

module Aws
  module S3
    module Encryption
      class Materials

        # @option options [required, OpenSSL::PKey::RSA, String] :key
        #   The master key to use for encrypting/decrypting all objects.
        #
        # @option options [String<JSON>] :description ('{}')
        #   The encryption materials description. This is must be
        #   a JSON document string.
        #
        def initialize(options = {})
          @key = validate_key(options[:key])
          @description = validate_desc(options[:description])
        end

        # @return [OpenSSL::PKey::RSA, String]
        attr_reader :key

        # @return [String<JSON>]
        attr_reader :description

        private

        def validate_key(key)
          case key
          when OpenSSL::PKey::RSA then key
          when String
            if [32, 24, 16].include?(key.bytesize)
              key
            else
              msg = "invalid key, symmetric key required to be 16, 24, or "
              msg << "32 bytes in length, saw length " + key.bytesize.to_s
              raise ArgumentError, msg
            end
          else
            msg = "invalid encryption key, expected an OpenSSL::PKey::RSA key "
            msg << "(for asymmetric encryption) or a String (for symmetric "
            msg << "encryption)."
            raise ArgumentError, msg
          end
        end

        def validate_desc(description)
          Json.load(description)
          description
        rescue Json::ParseError, EncodingError
          msg = "expected description to be a valid JSON document string"
          raise ArgumentError, msg
        end

      end
    end
  end
end

Version data entries

685 entries across 685 versions & 2 rubygems

Version Path
aws-sdk-resources-2.11.561 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.560 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.559 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.558 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.557 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.556 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.555 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.554 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.553 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.552 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.551 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.550 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.549 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.548 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.547 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.546 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.545 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.544 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.543 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.542 lib/aws-sdk-resources/services/s3/encryption/materials.rb