Class: Mongo::Crypt::ExplicitEncrypter Private
- Inherits:
-
Object
- Object
- Mongo::Crypt::ExplicitEncrypter
- Extended by:
- Forwardable
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/crypt/explicit_encrypter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
An ExplicitEncrypter is an object that performs explicit encryption operations and handles all associated options and instance variables.
Instance Method Summary collapse
-
#add_key_alt_name(id, key_alt_name) ⇒ BSON::Document | nil
private
Adds a key_alt_name for the key in the key vault collection with the given id.
-
#create_and_insert_data_key(master_key_document, key_alt_names, key_material = nil) ⇒ BSON::Binary
private
Generates a data key used for encryption/decryption and stores that key in the KMS collection.
-
#decrypt(value) ⇒ Object
private
Decrypts a value that has already been encrypted.
-
#encrypt(value, options) ⇒ BSON::Binary
private
Encrypts a value using the specified encryption key and algorithm.
-
#encrypt_expression(expression, options) ⇒ BSON::Binary
private
Encrypts a Match Expression or Aggregate Expression to query a range index.
-
#initialize(key_vault_client, key_vault_namespace, kms_providers, kms_tls_options) ⇒ ExplicitEncrypter
constructor
private
Create a new ExplicitEncrypter object.
-
#rewrap_many_data_key(filter, opts = {}) ⇒ Crypt::RewrapManyDataKeyResult
private
Decrypts multiple data keys and (re-)encrypts them with a new master_key, or with their current master_key if a new one is not given.
Constructor Details
#initialize(key_vault_client, key_vault_namespace, kms_providers, kms_tls_options) ⇒ ExplicitEncrypter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new ExplicitEncrypter object.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'build/ruby-driver-v2.19/lib/mongo/crypt/explicit_encrypter.rb', line 38 def initialize(key_vault_client, key_vault_namespace, kms_providers, ) Crypt.validate_ffi! @crypt_handle = Handle.new( kms_providers, , explicit_encryption_only: true ) @encryption_io = EncryptionIO.new( key_vault_client: key_vault_client, metadata_client: nil, key_vault_namespace: key_vault_namespace ) end |
Instance Method Details
#add_key_alt_name(id, key_alt_name) ⇒ BSON::Document | nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds a key_alt_name for the key in the key vault collection with the given id.
197 198 199 |
# File 'build/ruby-driver-v2.19/lib/mongo/crypt/explicit_encrypter.rb', line 197 def add_key_alt_name(id, key_alt_name) @encryption_io.add_key_alt_name(id, key_alt_name) end |
#create_and_insert_data_key(master_key_document, key_alt_names, key_material = nil) ⇒ BSON::Binary
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates a data key used for encryption/decryption and stores that key in the KMS collection. The generated key is encrypted with the KMS master key.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'build/ruby-driver-v2.19/lib/mongo/crypt/explicit_encrypter.rb', line 67 def create_and_insert_data_key(master_key_document, key_alt_names, key_material = nil) data_key_document = Crypt::DataKeyContext.new( @crypt_handle, @encryption_io, master_key_document, key_alt_names, key_material ).run_state_machine @encryption_io.insert_data_key(data_key_document).inserted_id end |
#decrypt(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Decrypts a value that has already been encrypted
182 183 184 185 186 187 188 |
# File 'build/ruby-driver-v2.19/lib/mongo/crypt/explicit_encrypter.rb', line 182 def decrypt(value) Crypt::ExplicitDecryptionContext.new( @crypt_handle, @encryption_io, { v: value } ).run_state_machine['v'] end |
#encrypt(value, options) ⇒ BSON::Binary
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The :key_id and :key_alt_name options are mutually exclusive. Only one is required to perform explicit encryption.
Encrypts a value using the specified encryption key and algorithm
if encryption algorithm is set to “Indexed”. Query type should be set
only if encryption algorithm is set to "Indexed". The only allowed
value is "equality".
108 109 110 111 112 113 114 115 |
# File 'build/ruby-driver-v2.19/lib/mongo/crypt/explicit_encrypter.rb', line 108 def encrypt(value, ) Crypt::ExplicitEncryptionContext.new( @crypt_handle, @encryption_io, { v: value }, ).run_state_machine['v'] end |
#encrypt_expression(expression, options) ⇒ BSON::Binary
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The RangePreview algorithm is experimental only. It is not
The :key_id and :key_alt_name options are mutually exclusive. Only one is required to perform explicit encryption.
Encrypts a Match Expression or Aggregate Expression to query a range index.
Only supported when queryType is “rangePreview” and algorithm is “RangePreview”. @note: The Range algorithm is experimental only. It is not intended
for public use. It is subject to breaking changes.
# @param [ Hash ] options intended for public use.
167 168 169 170 171 172 173 174 |
# File 'build/ruby-driver-v2.19/lib/mongo/crypt/explicit_encrypter.rb', line 167 def encrypt_expression(expression, ) Crypt::ExplicitEncryptionExpressionContext.new( @crypt_handle, @encryption_io, { v: expression }, ).run_state_machine['v'] end |
#rewrap_many_data_key(filter, opts = {}) ⇒ Crypt::RewrapManyDataKeyResult
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Decrypts multiple data keys and (re-)encrypts them with a new master_key,
or with their current master_key if a new one is not given.
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'build/ruby-driver-v2.19/lib/mongo/crypt/explicit_encrypter.rb', line 250 def rewrap_many_data_key(filter, opts = {}) (opts) master_key_document = master_key_for_provider(opts) rewrap_result = Crypt::RewrapManyDataKeyContext.new( @crypt_handle, @encryption_io, filter, master_key_document ).run_state_machine return RewrapManyDataKeyResult.new(nil) if rewrap_result.nil? updates = updates_from_data_key_documents(rewrap_result.fetch('v')) RewrapManyDataKeyResult.new(@encryption_io.update_data_keys(updates)) end |