Sha256: a8261348e4a4c4d83d28b5c83c89adcd750c2fe2d80b6228badad3f63f5ee368

Contents?: true

Size: 1.62 KB

Versions: 118

Compression:

Stored size: 1.62 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 31"
              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

118 entries across 118 versions & 2 rubygems

Version Path
aws-sdk-resources-2.3.23 lib/aws-sdk-resources/services/s3/encryption/materials.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/aws-sdk-resources-2.3.22/lib/aws-sdk-resources/services/s3/encryption/materials.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/aws-sdk-resources-2.3.22/lib/aws-sdk-resources/services/s3/encryption/materials.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/aws-sdk-resources-2.3.22/lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.6.1 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.6.0 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.5.11 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.5.10 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.5.8 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.5.7 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.5.6 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.5.5 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.5.4 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.5.3 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.5.2 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.5.1 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.5.0 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.4.4 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.4.3 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.4.2 lib/aws-sdk-resources/services/s3/encryption/materials.rb