Class: KmsEncrypted::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kms_encrypted/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_id: nil, legacy_context: false, data_key: false) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
# File 'lib/kms_encrypted/client.rb', line 5

def initialize(key_id: nil, legacy_context: false, data_key: false)
  @key_id = key_id || KmsEncrypted.key_id
  @legacy_context = legacy_context
  @data_key = data_key
end

Instance Attribute Details

#data_keyObject (readonly)

Returns the value of attribute data_key.



3
4
5
# File 'lib/kms_encrypted/client.rb', line 3

def data_key
  @data_key
end

#key_idObject (readonly)

Returns the value of attribute key_id.



3
4
5
# File 'lib/kms_encrypted/client.rb', line 3

def key_id
  @key_id
end

Instance Method Details

#decrypt(ciphertext, context: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kms_encrypted/client.rb', line 23

def decrypt(ciphertext, context: nil)
  event = {
    key_id: key_id,
    context: context,
    data_key: data_key
  }

  ActiveSupport::Notifications.instrument("decrypt.kms_encrypted", event) do
    client.decrypt(ciphertext, context: context)
  end
end

#encrypt(plaintext, context: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/kms_encrypted/client.rb', line 11

def encrypt(plaintext, context: nil)
  event = {
    key_id: key_id,
    context: context,
    data_key: data_key
  }

  ActiveSupport::Notifications.instrument("encrypt.kms_encrypted", event) do
    client.encrypt(plaintext, context: context)
  end
end