class Aws::S3::EncryptionV2::Materials

Attributes

description[R]

@return [String<JSON>]

key[R]

@return [OpenSSL::PKey::RSA, String]

Public Class Methods

new(options = {}) click to toggle source

@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.
# File lib/aws-sdk-s3/encryptionV2/materials.rb, line 17
def initialize(options = {})
  @key = validate_key(options[:key])
  @description = validate_desc(options[:description])
end

Private Instance Methods

validate_desc(description) click to toggle source
# File lib/aws-sdk-s3/encryptionV2/materials.rb, line 49
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
validate_key(key) click to toggle source
# File lib/aws-sdk-s3/encryptionV2/materials.rb, line 30
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