class Voynich::KMSDataKeyClient

Constants

Result

Attributes

cmk_id[R]

Public Class Methods

new(cmk_id) click to toggle source
# File lib/voynich/kms_data_key_client.rb, line 7
def initialize(cmk_id)
  @cmk_id = cmk_id
end

Public Instance Methods

decrypt(ciphertext) click to toggle source
# 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
generate() click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

decode(data) click to toggle source
# File lib/voynich/kms_data_key_client.rb, line 35
def decode(data)
  Base64.decode64(data)
end
encode(data) click to toggle source
# File lib/voynich/kms_data_key_client.rb, line 31
def encode(data)
  Base64.strict_encode64(data)
end
kms_client() click to toggle source
# File lib/voynich/kms_data_key_client.rb, line 39
def kms_client
  @kms_client ||= Voynich.kms_client
end