Class: KmsEncrypted::Clients::Google
- Defined in:
- lib/kms_encrypted/clients/google.rb
Instance Attribute Summary collapse
-
#last_key_version ⇒ Object
readonly
Returns the value of attribute last_key_version.
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from KmsEncrypted::Clients::Base
Instance Attribute Details
#last_key_version ⇒ Object (readonly)
Returns the value of attribute last_key_version.
4 5 6 |
# File 'lib/kms_encrypted/clients/google.rb', line 4 def last_key_version @last_key_version end |
Instance Method Details
#decrypt(ciphertext, context: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kms_encrypted/clients/google.rb', line 22 def decrypt(ciphertext, context: nil) = { ciphertext: ciphertext } [:additional_authenticated_data] = generate_context(context) if context # ensure namespace gets loaded client = KmsEncrypted.google_client request = ::Google::Apis::CloudkmsV1::DecryptRequest.new(**) begin client.decrypt_crypto_key(key_id, request).plaintext rescue ::Google::Apis::ClientError => e decryption_failed! if e..include?("Decryption failed") raise e end end |
#encrypt(plaintext, context: nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/kms_encrypted/clients/google.rb', line 6 def encrypt(plaintext, context: nil) = { plaintext: plaintext } [:additional_authenticated_data] = generate_context(context) if context # ensure namespace gets loaded client = KmsEncrypted.google_client request = ::Google::Apis::CloudkmsV1::EncryptRequest.new(**) response = client.encrypt_crypto_key(key_id, request) @last_key_version = response.name response.ciphertext end |