Sha256: be4b7384d023ea727d49d085a4668babae716ed08eb0d5e6aa3819cd944a0b19

Contents?: true

Size: 1.68 KB

Versions: 211

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

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 '\
                    '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 '\
                  '(for asymmetric encryption) or a String (for symmetric '\
                  '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

211 entries across 211 versions & 2 rubygems

Version Path
aws-sdk-resources-2.11.579 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.578 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.577 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.576 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.575 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.574 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.573 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-s3-1.79.1 lib/aws-sdk-s3/encryption/materials.rb
aws-sdk-s3-1.79.0 lib/aws-sdk-s3/encryption/materials.rb
aws-sdk-resources-2.11.572 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.571 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.570 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.569 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.568 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.567 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.566 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-resources-2.11.565 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-s3-1.78.0 lib/aws-sdk-s3/encryption/materials.rb
aws-sdk-resources-2.11.564 lib/aws-sdk-resources/services/s3/encryption/materials.rb
aws-sdk-s3-1.77.0 lib/aws-sdk-s3/encryption/materials.rb