Class: SecureDataBag::NestedEncryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/secure_data_bag/encryptor.rb

Overview

Encryptor object responsable for encrypting the raw_hash with the secret. This object will recursively step through the raw_hash, looking for keys matching encrypted_keys and encrypt their values.

Since:

  • 3.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(decrypted_hash, secret, metadata = {}) ⇒ NestedEncryptor

Initializer

Parameters:

  • decrypted_hash (Hash, String)

    the encrypted hash to encrypt

  • secret (String)

    the secret to encrypt with

  • metadata (Hash) (defaults to: {})

    optional metadata

Since:

  • 3.0.0



118
119
120
121
122
123
124
125
126
127
# File 'lib/secure_data_bag/encryptor.rb', line 118

def initialize(decrypted_hash, secret,  = {})
  @secret = secret
  @metadata = 
  @encrypted_hash = {}
  @encrypted_keys = case [:encryption_format]
                    when 'plain' then @encrypted_keys = []
                    else [:encrypted_keys] || []
                    end
  @decrypted_hash = decrypted_hash
end

Instance Attribute Details

#decrypted_hashObject (readonly)

The decrypted hash to encrypt

Since:

  • 3.0.0



108
109
110
# File 'lib/secure_data_bag/encryptor.rb', line 108

def decrypted_hash
  @decrypted_hash
end

#encrypted_hashObject (readonly)

The encrypted hash generated

Since:

  • 3.0.0



104
105
106
# File 'lib/secure_data_bag/encryptor.rb', line 104

def encrypted_hash
  @encrypted_hash
end

#encrypted_keysObject (readonly)

The keys to encrypt

Since:

  • 3.0.0



100
101
102
# File 'lib/secure_data_bag/encryptor.rb', line 100

def encrypted_keys
  @encrypted_keys
end

#metadataObject (readonly)

The metadata used to create the encrypted_hash

Since:

  • 3.0.0



111
112
113
# File 'lib/secure_data_bag/encryptor.rb', line 111

def 
  @metadata
end

Instance Method Details

#encryptHash

Method called to encrpt the data structure and return it.

Returns:

  • (Hash)

    the encrypted value

Since:

  • 3.0.0



139
140
141
# File 'lib/secure_data_bag/encryptor.rb', line 139

def encrypt
  encrypt_data(@decrypted_hash)
end

#encrypt!Hash Also known as: for_encrypted_item

Method called to encrpt the data structure and return it.

Returns:

  • (Hash)

    the encrypted value

Since:

  • 3.0.0



132
133
134
# File 'lib/secure_data_bag/encryptor.rb', line 132

def encrypt!
  @encrypted_hash = encrypt
end