Class: Voynich::KMSDataKeyClient

Inherits:
Object
  • Object
show all
Defined in:
lib/voynich/kms_data_key_client.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmk_id) ⇒ KMSDataKeyClient

Returns a new instance of KMSDataKeyClient.



7
8
9
# File 'lib/voynich/kms_data_key_client.rb', line 7

def initialize(cmk_id)
  @cmk_id = cmk_id
end

Instance Attribute Details

#cmk_idObject (readonly)

Returns the value of attribute cmk_id.



5
6
7
# File 'lib/voynich/kms_data_key_client.rb', line 5

def cmk_id
  @cmk_id
end

Instance Method Details

#decrypt(ciphertext) ⇒ Object



11
12
13
14
# File 'lib/voynich/kms_data_key_client.rb', line 11

def decrypt(ciphertext)
  response = kms_client.decrypt(ciphertext_blob: decode(ciphertext))
  Result.new(encode(response.plaintext), ciphertext)
end

#generateObject



16
17
18
19
# File 'lib/voynich/kms_data_key_client.rb', line 16

def generate
  response = kms_client.generate_data_key(key_id: cmk_id, key_spec: 'AES_256')
  Result.new(encode(response.plaintext), encode(response.ciphertext_blob))
end

#reencrypt(ciphertext) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/voynich/kms_data_key_client.rb', line 21

def reencrypt(ciphertext)
  response = kms_client.re_encrypt(
    ciphertext_blob: decode(ciphertext),
    destination_key_id: cmk_id
  )
  Result.new(nil, encode(response.ciphertext_blob))
end