Class: SecureDataBag::FlatEncryptor

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 is just a wrapper around Chef::EncryptedDataBagItem.

Since:

  • 3.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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



55
56
57
58
59
60
61
# File 'lib/secure_data_bag/encryptor.rb', line 55

def initialize(decrypted_hash, secret,  = {})
  @secret = secret
  @metadata = 
  @encrypted_hash = {}
  @encrypted_keys = []
  @decrypted_hash = decrypted_hash
end

Instance Attribute Details

#decrypted_hashObject (readonly)

The decrypted hash to encrypt

Since:

  • 3.0.0



45
46
47
# File 'lib/secure_data_bag/encryptor.rb', line 45

def decrypted_hash
  @decrypted_hash
end

#encrypted_hashObject (readonly)

The encrypted hash generated

Since:

  • 3.0.0



41
42
43
# File 'lib/secure_data_bag/encryptor.rb', line 41

def encrypted_hash
  @encrypted_hash
end

#encrypted_keysObject (readonly)

The keys to encrypt

Since:

  • 3.0.0



37
38
39
# File 'lib/secure_data_bag/encryptor.rb', line 37

def encrypted_keys
  @encrypted_keys
end

#metadataObject (readonly)

The metadata used to create the encrypted_hash

Since:

  • 3.0.0



48
49
50
# File 'lib/secure_data_bag/encryptor.rb', line 48

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



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/secure_data_bag/encryptor.rb', line 73

def encrypt
  ## NO WORKY
  ## NO WORKY
  ## NO WORKY
  ## NO WORKY
  ## NO WORKY
  ## NO WORKY
  Chef::EncryptedDataBagItem.encrypt_data_bag_item(
    @decrypted_hash,
    @secret
  )
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



66
67
68
# File 'lib/secure_data_bag/encryptor.rb', line 66

def encrypt!
  @encrypted_hash = encrypt
end