Class: Portunus::DataKeyGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/portunus/data_key_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encrypted_object:, encrypter: ::Portunus.configuration.encrypter, key_finder: Portunus.configuration.storage_adaptor) ⇒ DataKeyGenerator

Returns a new instance of DataKeyGenerator.



7
8
9
10
11
12
13
14
15
# File 'lib/portunus/data_key_generator.rb', line 7

def initialize(
  encrypted_object:,
  encrypter: ::Portunus.configuration.encrypter,
  key_finder: Portunus.configuration.storage_adaptor
)
  @encrypter = encrypter
  @key_finder = key_finder
  @encrypted_object = encrypted_object
end

Class Method Details

.generate(encrypted_object) ⇒ Object



3
4
5
# File 'lib/portunus/data_key_generator.rb', line 3

def self.generate(encrypted_object)
  new(encrypted_object: encrypted_object).generate
end

Instance Method Details

#generateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/portunus/data_key_generator.rb', line 17

def generate
  dek = encrypted_object.build_data_encryption_key(
    encrypted_key: new_encrypted_key,
    master_keyname: master_keyname
  )

  if dek.key != new_plaintext_key
    raise ::Portunus::Error.new(
      "Dek Key creation failed: Decrypted key does not match the original"
    )
  end

  dek
end