Sha256: 9a9d6edd673b60a86a7be8bce2a1ba957b058e9c693a4ed37323e2dbecec7343

Contents?: true

Size: 1.64 KB

Versions: 214

Compression:

Stored size: 1.64 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
          msg = "expected description to be a valid JSON document string"
          raise ArgumentError, msg
        end

      end
    end
  end
end

Version data entries

214 entries across 214 versions & 2 rubygems

Version Path
aws-sdk-resources-2.10.75 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.74 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.73 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.72 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.71 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.70 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.69 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.68 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.67 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.66 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.65 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.64 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.63 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.62 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.61 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.60 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.59 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.58 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.57 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.10.56 lib/aws-sdk-resources/services/s3/encryption/materials.rb