Class: Mongo::Crypt::Binding Private
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
FFI::Library
|
|
Inherits: | Object |
Defined in: | lib/mongo/crypt/binding.rb |
Overview
A Ruby binding for the libmongocrypt C library
Constant Summary
-
MIN_LIBMONGOCRYPT_VERSION =
Minimum version of libmongocrypt required by this version of the driver. An attempt to use the driver with any previous version of libmongocrypt will cause a
LoadError
.Gem::Version.new("1.12.0")
Class Method Summary
-
.check_ctx_status(context) ⇒ nil
Internal use only
Raise a Mongo::Error::CryptError based on the status of the underlying mongocrypt_ctx_t object.
-
.check_kms_ctx_status(kms_context)
Internal use only
If the provided block returns false, raise a CryptError with the status information from the provided
KmsContext
object. -
.check_status(handle) ⇒ nil
Internal use only
Raise a Mongo::Error::CryptError based on the status of the underlying mongocrypt_t object.
-
.crypt_shared_lib_version(handle) ⇒ Integer
Internal use only
Obtain a 64-bit constant encoding the version of the loaded crypt_shared library, if available.
-
.ctx_datakey_init(context)
Internal use only
Initialize the
Context
to create a data key. -
.ctx_decrypt_init(context, command)
Internal use only
Initialize the
Context
for auto-decryption. -
.ctx_encrypt_init(context, db_name, command)
Internal use only
Initialize the
Context
for auto-encryption. -
.ctx_explicit_decrypt_init(context, doc)
Internal use only
Initialize the
Context
for explicit decryption. -
.ctx_explicit_encrypt_expression_init(context, doc)
Internal use only
Initialize the
Context
for explicit expression encryption. -
.ctx_explicit_encrypt_init(context, doc)
Internal use only
Initialize the
Context
for explicit encryption. -
.ctx_finalize(context)
Internal use only
Finalize the state machine represented by the
Context
. -
.ctx_kms_done(context)
Internal use only
Indicate to libmongocrypt that it will receive no more
KMS
replies. -
.ctx_mongo_feed(context, doc)
Internal use only
Feed a response from the driver back to libmongocrypt.
-
.ctx_mongo_op(context) ⇒ BSON::Document
Internal use only
Returns a BSON::Document representing an operation that the driver must perform on behalf of libmongocrypt to get the information it needs in order to continue with encryption/decryption (for example, a filter for a key vault query).
-
.ctx_next_kms_ctx(context) ⇒ Mongo::Crypt::KmsContext | nil
Internal use only
Return a new
KmsContext
object needed by aContext
object. -
.ctx_provide_kms_providers(context, kms_providers)
Internal use only
Call in response to the MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS state to set per-context
KMS
provider settings. -
.ctx_rewrap_many_datakey_init(context, filter) ⇒ Boolean
Internal use only
Initialize a context to rewrap datakeys.
-
.ctx_setopt_algorithm(context, name)
Internal use only
Set the algorithm on the context.
-
.ctx_setopt_algorithm_range(context, opts)
Internal use only
Set options for explicit encryption with the “range” algorithm.
-
.ctx_setopt_contention_factor(context, factor)
Internal use only
Set the contention factor used for explicit encryption.
-
.ctx_setopt_key_alt_names(context, key_alt_names)
Internal use only
Set multiple alternate key names on data key creation.
-
.ctx_setopt_key_encryption_key(context, key_document)
Internal use only
Set key encryption key document for creating a data key.
-
.ctx_setopt_key_id(context, key_id)
Internal use only
Sets the key id option on an explicit encryption context.
-
.ctx_setopt_key_material(context, key_material)
Internal use only
Set set a custom key material to use for.
-
.ctx_setopt_query_type(context, query_type)
Internal use only
Set the query type to use for FLE 2 explicit encryption.
- .get_binary_data_direct(mongocrypt_binary_t) Internal use only
- .get_binary_len_direct(mongocrypt_binary_t) Internal use only
-
.init(handle)
Internal use only
Initialize the Mongo::Crypt::Handle object.
-
.kms_ctx_bytes_needed(kms_context) ⇒ Integer
Internal use only
Get the number of bytes needed by the
KmsContext
. -
.kms_ctx_endpoint(kms_context) ⇒ String | nil
Internal use only
Get the hostname with which to connect over TLS to get information about the AWS master key.
-
.kms_ctx_fail(kms_context) ⇒ true, false
Internal use only
Check whether the last failed request for the
KMS
context may be retried. -
.kms_ctx_feed(kms_context, bytes)
Internal use only
Feed replies from the
KMS
back to libmongocrypt. - .kms_ctx_get_kms_provider(kms_context) Internal use only
-
.kms_ctx_message(kms_context) ⇒ String
Internal use only
Get the HTTP message needed to fetch the AWS KMS master key from a
KmsContext
object. -
.kms_ctx_setopt_retry_kms(handle, value) ⇒ true, fale
Internal use only
Enable or disable
KMS
retry behavior. - .kms_ctx_usleep(kms_context) ⇒ Integer Internal use only
-
.mongocrypt_binary_data(binary) ⇒ FFI::Pointer
Internal use only
Get the pointer to the underlying data for the mongocrypt_binary_t.
-
.mongocrypt_binary_destroy(binary) ⇒ nil
Internal use only
Destroy the mongocrypt_binary_t object.
-
.mongocrypt_binary_len(binary) ⇒ Integer
Internal use only
Get the length of the underlying data array.
-
.mongocrypt_binary_new ⇒ FFI::Pointer
Internal use only
Creates a new mongocrypt_binary_t object (a non-owning view of a byte.
-
.mongocrypt_binary_new_from_data(data, len) ⇒ FFI::Pointer
Internal use only
Create a new mongocrypt_binary_t object that maintains a pointer to.
- .mongocrypt_crypt_shared_lib_version(crypt) Internal use only
- .mongocrypt_ctx_datakey_init(ctx, filter) Internal use only
-
.mongocrypt_ctx_decrypt_init(ctx, doc) ⇒ Boolean
Internal use only
Initializes the ctx for auto-decryption.
-
.mongocrypt_ctx_destroy(ctx) ⇒ nil
Internal use only
Destroy the reference to the mongocrypt_ctx_t object.
-
.mongocrypt_ctx_encrypt_init(ctx, db, db_len, cmd) ⇒ Boolean
Internal use only
Initializes the ctx for auto-encryption.
-
.mongocrypt_ctx_explicit_decrypt_init(ctx, msg) ⇒ Boolean
Internal use only
Initializes the ctx for explicit decryption.
-
.mongocrypt_ctx_explicit_encrypt_init(ctx, msg) ⇒ Boolean
Internal use only
Initializes the ctx for explicit expression encryption.
-
.mongocrypt_ctx_finalize(ctx, op_bson) ⇒ Boolean
Internal use only
Perform the final encryption or decryption and return a BSON document.
-
.mongocrypt_ctx_mongo_done(ctx) ⇒ Boolean
Internal use only
Indicate to libmongocrypt that the driver is done feeding replies.
-
.mongocrypt_ctx_mongo_feed(ctx, reply) ⇒ Boolean
Internal use only
Feed a BSON reply to libmongocrypt.
-
.mongocrypt_ctx_mongo_next_kms_ctx(ctx) ⇒ FFI::Pointer
Internal use only
Return a pointer to a mongocrypt_kms_ctx_t object or NULL.
-
.mongocrypt_ctx_mongo_op(ctx, op_bson) ⇒ Boolean
Internal use only
Get a BSON operation for the driver to run against the MongoDB.
-
.mongocrypt_ctx_new(crypt) ⇒ FFI::Pointer
Internal use only
Create a new mongocrypt_ctx_t object (a wrapper for the libmongocrypt.
- .mongocrypt_ctx_provide_kms_providers(ctx, kms_providers) Internal use only
-
.mongocrypt_ctx_setopt_algorithm(ctx, algorithm, len) ⇒ Boolean
Internal use only
Set the algorithm used for explicit encryption.
- .mongocrypt_ctx_setopt_algorithm_range(ctx, opts) Internal use only
- .mongocrypt_ctx_setopt_contention_factor(ctx, contention_factor) Internal use only
-
.mongocrypt_ctx_setopt_key_alt_name(ctx, binary) ⇒ Boolean
Internal use only
When creating a data key, set an alternate name on that key.
-
.mongocrypt_ctx_setopt_key_encryption_key(ctx) ⇒ Boolean
Internal use only
Set key encryption key document for creating a data key.
-
.mongocrypt_ctx_setopt_key_id(ctx, key_id) ⇒ Boolean
Internal use only
Set the key id used for explicit encryption.
-
.mongocrypt_ctx_setopt_key_material(ctx, binary) ⇒ Boolean
Internal use only
When creating a data key, set a custom key material to use for.
- .mongocrypt_ctx_setopt_query_type(ctx, mongocrypt_query_type) Internal use only
-
.mongocrypt_ctx_state(ctx) ⇒ Symbol
Internal use only
Get the current state of the ctx.
-
.mongocrypt_ctx_status(ctx, status) ⇒ Boolean
Internal use only
Set the status information from the mongocrypt_ctx_t object on the.
-
.mongocrypt_destroy(crypt) ⇒ nil
Internal use only
Destroy the reference the mongocrypt_t object.
-
.mongocrypt_init(crypt) ⇒ Boolean
Internal use only
Initialize the mongocrypt_t object.
-
.mongocrypt_kms_ctx_bytes_needed(kms) ⇒ Integer
Internal use only
Get the number of bytes needed by the
KMS
context. -
.mongocrypt_kms_ctx_done(ctx) ⇒ Boolean
Internal use only
Indicate to libmongocrypt that it will receive no more replies from.
-
.mongocrypt_kms_ctx_endpoint(kms, endpoint) ⇒ Boolean
Internal use only
Get the hostname with which to connect over TLS to get information about.
- .mongocrypt_kms_ctx_fail(ctx) Internal use only
-
.mongocrypt_kms_ctx_feed(kms, bytes) ⇒ Boolean
Internal use only
Feed replies from the
KMS
back to libmongocrypt. - .mongocrypt_kms_ctx_get_kms_provider(crypt, kms_providers) Internal use only
-
.mongocrypt_kms_ctx_message(kms, msg) ⇒ Boolean
Internal use only
Get the message needed to fetch the AWS KMS master key.
-
.mongocrypt_kms_ctx_status(kms, status) ⇒ Boolean
Internal use only
Write status information about the mongocrypt_kms_ctx_t object.
-
.mongocrypt_kms_ctx_usleep(ctx) ⇒ int64
Internal use only
Indicates how long to sleep before sending
KMS
request. -
.mongocrypt_setopt_aes_256_ctr(crypt, aes_256_ctr_encrypt, aes_256_ctr_decrypt, ctx) ⇒ Boolean
Internal use only
Set a crypto hook for the AES256-CTR operations.
- .mongocrypt_setopt_append_crypt_shared_lib_search_path(crypt, path) Internal use only
- .mongocrypt_setopt_bypass_query_analysis(crypt) Internal use only
-
.mongocrypt_setopt_crypto_hook_sign_rsaes_pkcs1_v1_5(crypt, sign_rsaes_pkcs1_v1_5, ctx = nil) ⇒ Boolean
Internal use only
Set a crypto hook for the RSASSA-PKCS1-v1_5 algorithm with a SHA-256 hash.
-
.mongocrypt_setopt_crypto_hooks(crypt, aes_enc_fn, aes_dec_fn, random_fn, sha_512_fn, sha_256_fn, hash_fn, ctx = nil) ⇒ Boolean
Internal use only
Set crypto hooks on the provided mongocrypt object.
- .mongocrypt_setopt_encrypted_field_config_map(crypt, efc_map) Internal use only
-
.mongocrypt_setopt_kms_providers(crypt, kms_providers)
Internal use only
Configure KMS providers with a BSON document.
-
.mongocrypt_setopt_log_handler(crypt, log_fn, log_ctx = nil) ⇒ Boolean
Internal use only
Set the handler on the mongocrypt_t object to be called every time.
- .mongocrypt_setopt_retry_kms(crypt, enable) Internal use only
-
.mongocrypt_setopt_schema_map(crypt, schema_map) ⇒ Boolean
Internal use only
Sets a local schema map for encryption.
- .mongocrypt_setopt_set_crypt_shared_lib_path_override(crypt, path) Internal use only
- .mongocrypt_setopt_use_need_kms_credentials_state(crypt) Internal use only
-
.mongocrypt_status(crypt, status) ⇒ Boolean
Internal use only
Set the status information from the mongocrypt_t object on the.
-
.mongocrypt_status_code(status) ⇒ Integer
Internal use only
Return the status error code.
-
.mongocrypt_status_destroy(status) ⇒ nil
Internal use only
Destroys the reference to the mongocrypt_status_t object.
-
.mongocrypt_status_message(status, len = nil) ⇒ String
Internal use only
Returns the status message.
-
.mongocrypt_status_new ⇒ FFI::Pointer
Internal use only
Create a new mongocrypt_status_t object.
-
.mongocrypt_status_ok(status) ⇒ Boolean
Internal use only
Returns whether the status is ok or an error.
-
.mongocrypt_status_set(status, type, code, message, len) ⇒ nil
Internal use only
Set a message, type, and code on an existing status.
-
.mongocrypt_status_type(status) ⇒ Symbol
Internal use only
Indicates the status type.
-
.mongocrypt_version(len) ⇒ String
Internal use only
Returns the version string of the libmongocrypt library.
-
.ongocrypt_new ⇒ FFI::Pointer
Internal use only
Creates a new mongocrypt_t object.
-
.parse_version(version) ⇒ Gem::Version
Internal use only
Given a string representing a version number, parses it into a Gem::Version object.
-
.setopt_aes_256_ctr(handle, aes_ctr_encrypt_cb, aes_ctr_decrypt_cb)
Internal use only
Set a crypto hook for the AES256-CTR operations.
-
.setopt_append_crypt_shared_lib_search_path(handle, path)
Internal use only
Append an additional search directory to the search path for loading.
-
.setopt_bypass_query_analysis(handle)
Internal use only
Opt-into skipping query analysis.
-
.setopt_crypto_hook_sign_rsaes_pkcs1_v1_5(handle, rsaes_pkcs_signature_cb)
Internal use only
Set a crypto hook for the RSASSA-PKCS1-v1_5 algorithm with.
-
.setopt_crypto_hooks(handle, aes_encrypt_cb, aes_decrypt_cb, random_cb, hmac_sha_512_cb, hmac_sha_256_cb, hmac_hash_cb)
Internal use only
Set crypto callbacks on the
Handle
. -
.setopt_encrypted_field_config_map(handle, efc_map)
Internal use only
Set a local EncryptedFieldConfigMap for encryption.
-
.setopt_kms_providers(handle, kms_providers)
Internal use only
Set KMS providers options on the Mongo::Crypt::Handle object.
-
.setopt_log_handler(handle, log_callback)
Internal use only
Set the logger callback function on the Mongo::Crypt::Handle object.
-
.setopt_schema_map(handle, schema_map_doc)
Internal use only
Set schema map on the Mongo::Crypt::Handle object.
-
.setopt_set_crypt_shared_lib_path_override(handle, path)
Internal use only
Set a single override path for loading the crypt shared library.
-
.setopt_use_need_kms_credentials_state(handle)
Internal use only
Opt-into handling the MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS state.
-
.validate_document(data)
Internal use only
Checks that the specified data is a Hash before serializing it to BSON to prevent errors from libmongocrypt.
-
.validate_version(lmc_version)
Internal use only
Validates if provided version of libmongocrypt is valid, i.e. equal or greater than minimum required version.
Instance Method Summary
-
#mongocrypt_crypto_fn(ctx, key, iv, input, output, status) ⇒ Bool
Internal use only
A callback to a function that performs AES encryption or decryption.
-
#mongocrypt_hash_fn(ctx, input, output, status) ⇒ Bool
Internal use only
A callback to a SHA-256 hash function.
-
#mongocrypt_hmac_fn(ctx, key, input, output, status) ⇒ Bool
Internal use only
A callback to a function that performs HMAC SHA-512 or SHA-256.
-
#mongocrypt_log_fn_t(level, message, len, ctx) ⇒ nil
Internal use only
A callback to the mongocrypt log function.
-
#mongocrypt_random_fn(ctx, output, count, status) ⇒ Bool
Internal use only
A callback to a crypto secure random function.
Class Method Details
.check_ctx_status(context) ⇒ nil
Raise a Mongo::Error::CryptError based on the status of the underlying mongocrypt_ctx_t object.
# File 'lib/mongo/crypt/binding.rb', line 1821
def self.check_ctx_status(context) if block_given? do_raise = !yield else do_raise = true end if do_raise status = Status.new mongocrypt_ctx_status(context.ctx_p, status.ref) status.raise_crypt_error end end
.check_kms_ctx_status(kms_context)
If the provided block returns false, raise a CryptError with the status information from the provided KmsContext
object.
# File 'lib/mongo/crypt/binding.rb', line 1107
def self.check_kms_ctx_status(kms_context) unless yield status = Status.new mongocrypt_kms_ctx_status(kms_context.kms_ctx_p, status.ref) status.raise_crypt_error(kms: true) end end
.check_status(handle) ⇒ nil
Raise a Mongo::Error::CryptError based on the status of the underlying mongocrypt_t object.
# File 'lib/mongo/crypt/binding.rb', line 1808
def self.check_status(handle) unless yield status = Status.new mongocrypt_status(handle.ref, status.ref) status.raise_crypt_error end end
.ctx_datakey_init(context)
Initialize the Context
to create a data key
# File 'lib/mongo/crypt/binding.rb', line 625
def self.ctx_datakey_init(context) check_ctx_status(context) do mongocrypt_ctx_datakey_init(context.ctx_p) end end
.ctx_decrypt_init(context, command)
Initialize the Context
for auto-decryption
# File 'lib/mongo/crypt/binding.rb', line 786
def self.ctx_decrypt_init(context, command) validate_document(command) data = command.to_bson.to_s Binary.wrap_string(data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_decrypt_init(context.ctx_p, data_p) end end end
.ctx_encrypt_init(context, db_name, command)
Initialize the Context
for auto-encryption
# File 'lib/mongo/crypt/binding.rb', line 692
def self.ctx_encrypt_init(context, db_name, command) validate_document(command) data = command.to_bson.to_s Binary.wrap_string(data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_encrypt_init(context.ctx_p, db_name, -1, data_p) end end end
.ctx_explicit_decrypt_init(context, doc)
Initialize the Context
for explicit decryption
# File 'lib/mongo/crypt/binding.rb', line 816
def self.ctx_explicit_decrypt_init(context, doc) validate_document(doc) data = doc.to_bson.to_s Binary.wrap_string(data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_explicit_decrypt_init(context.ctx_p, data_p) end end end
.ctx_explicit_encrypt_expression_init(context, doc)
Initialize the Context
for explicit expression encryption.
# File 'lib/mongo/crypt/binding.rb', line 760
def self.ctx_explicit_encrypt_expression_init(context, doc) validate_document(doc) data = doc.to_bson.to_s Binary.wrap_string(data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_explicit_encrypt_expression_init(context.ctx_p, data_p) end end end
.ctx_explicit_encrypt_init(context, doc)
Initialize the Context
for explicit encryption
# File 'lib/mongo/crypt/binding.rb', line 726
def self.ctx_explicit_encrypt_init(context, doc) validate_document(doc) data = doc.to_bson.to_s Binary.wrap_string(data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_explicit_encrypt_init(context.ctx_p, data_p) end end end
.ctx_finalize(context)
Finalize the state machine represented by the Context
# File 'lib/mongo/crypt/binding.rb', line 1209
def self.ctx_finalize(context) binary = Binary.new check_ctx_status(context) do mongocrypt_ctx_finalize(context.ctx_p, binary.ref) end # TODO since the binary references a C pointer, and ByteBuffer is # written in C in MRI, we could omit a copy of the data by making # ByteBuffer reference the string that is owned by libmongocrypt. BSON::Document.from_bson(BSON::ByteBuffer.new(binary.to_s), mode: :bson) end
.ctx_kms_done(context)
Indicate to libmongocrypt that it will receive no more KMS
replies.
# File 'lib/mongo/crypt/binding.rb', line 1186
def self.ctx_kms_done(context) check_ctx_status(context) do mongocrypt_ctx_kms_done(context.ctx_p) end end
.ctx_mongo_feed(context, doc)
Feed a response from the driver back to libmongocrypt
# File 'lib/mongo/crypt/binding.rb', line 897
def self.ctx_mongo_feed(context, doc) validate_document(doc) data = doc.to_bson.to_s Binary.wrap_string(data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_mongo_feed(context.ctx_p, data_p) end end end
.ctx_mongo_op(context) ⇒ BSON::Document
Returns a BSON::Document representing an operation that the driver must perform on behalf of libmongocrypt to get the information it needs in order to continue with encryption/decryption (for example, a filter for a key vault query).
# File 'lib/mongo/crypt/binding.rb', line 868
def self.ctx_mongo_op(context) binary = Binary.new check_ctx_status(context) do mongocrypt_ctx_mongo_op(context.ctx_p, binary.ref) end # TODO since the binary references a C pointer, and ByteBuffer is # written in C in MRI, we could omit a copy of the data by making # ByteBuffer reference the string that is owned by libmongocrypt. BSON::Document.from_bson(BSON::ByteBuffer.new(binary.to_s), mode: :bson) end
.ctx_next_kms_ctx(context) ⇒ Mongo::Crypt::KmsContext | nil
Return a new KmsContext
object needed by a Context
object.
# File 'lib/mongo/crypt/binding.rb', line 929
def self.ctx_next_kms_ctx(context) kms_ctx_p = mongocrypt_ctx_next_kms_ctx(context.ctx_p) if kms_ctx_p.null? nil else KmsContext.new(kms_ctx_p) end end
.ctx_provide_kms_providers(context, kms_providers)
Call in response to the MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS state to set per-context KMS
provider settings. These follow the same format as ‘mongocrypt_setopt_kms_providers“. If no keys are present in the BSON input, the KMS
provider settings configured for the mongocrypt_t at initialization are used.
# File 'lib/mongo/crypt/binding.rb', line 1687
def self.ctx_provide_kms_providers(context, kms_providers) validate_document(kms_providers) data = kms_providers.to_bson.to_s Binary.wrap_string(data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_provide_kms_providers(context.ctx_p, data_p) end end end
.ctx_rewrap_many_datakey_init(context, filter) ⇒ Boolean
Initialize a context to rewrap datakeys.
# File 'lib/mongo/crypt/binding.rb', line 656
def self.ctx_rewrap_many_datakey_init(context, filter) filter_data = filter.to_bson.to_s Binary.wrap_string(filter_data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_rewrap_many_datakey_init(context.ctx_p, data_p) end end end
.ctx_setopt_algorithm(context, name)
Set the algorithm on the context
# File 'lib/mongo/crypt/binding.rb', line 569
def self.ctx_setopt_algorithm(context, name) check_ctx_status(context) do mongocrypt_ctx_setopt_algorithm(context.ctx_p, name, -1) end end
.ctx_setopt_algorithm_range(context, opts)
The Range algorithm is experimental only. It is not intended for
Set options for explicit encryption with the “range” algorithm.
public use.
# File 'lib/mongo/crypt/binding.rb', line 1794
def self.ctx_setopt_algorithm_range(context, opts) validate_document(opts) data = opts.to_bson.to_s Binary.wrap_string(data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_setopt_algorithm_range(context.ctx_p, data_p) end end end
.ctx_setopt_contention_factor(context, factor)
Set the contention factor used for explicit encryption. The contention factor is only used for indexed FLE 2 encryption.
# File 'lib/mongo/crypt/binding.rb', line 1757
def self.ctx_setopt_contention_factor(context, factor) check_ctx_status(context) do mongocrypt_ctx_setopt_contention_factor(context.ctx_p, factor) end end
.ctx_setopt_key_alt_names(context, key_alt_names)
Set multiple alternate key names on data key creation
# File 'lib/mongo/crypt/binding.rb', line 500
def self.ctx_setopt_key_alt_names(context, key_alt_names) key_alt_names.each do |key_alt_name| key_alt_name_bson = { :keyAltName => key_alt_name }.to_bson.to_s Binary.wrap_string(key_alt_name_bson) do |key_alt_name_p| check_ctx_status(context) do mongocrypt_ctx_setopt_key_alt_name(context.ctx_p, key_alt_name_p) end end end end
.ctx_setopt_key_encryption_key(context, key_document)
Set key encryption key document for creating a data key.
# File 'lib/mongo/crypt/binding.rb', line 598
def self.ctx_setopt_key_encryption_key(context, key_document) validate_document(key_document) data = key_document.to_bson.to_s Binary.wrap_string(data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_setopt_key_encryption_key(context.ctx_p, data_p) end end end
.ctx_setopt_key_id(context, key_id)
Sets the key id option on an explicit encryption context.
# File 'lib/mongo/crypt/binding.rb', line 467
def self.ctx_setopt_key_id(context, key_id) Binary.wrap_string(key_id) do |key_id_p| check_ctx_status(context) do mongocrypt_ctx_setopt_key_id(context.ctx_p, key_id_p) end end end
.ctx_setopt_key_material(context, key_material)
Set set a custom key material to use for
encrypting data.
# File 'lib/mongo/crypt/binding.rb', line 535
def self.ctx_setopt_key_material(context, key_material) data = {'keyMaterial' => key_material}.to_bson.to_s Binary.wrap_string(data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_setopt_key_material(context.ctx_p, data_p) end end end
.ctx_setopt_query_type(context, query_type)
Set the query type to use for FLE 2 explicit encryption. The query type is only used for indexed FLE 2 encryption.
# File 'lib/mongo/crypt/binding.rb', line 1725
def self.ctx_setopt_query_type(context, query_type) check_ctx_status(context) do mongocrypt_ctx_setopt_query_type(context.ctx_p, query_type, -1) end end
.get_binary_data_direct(mongocrypt_binary_t)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 181
def self.get_binary_data_direct(mongocrypt_binary_t) mongocrypt_binary_t.get_pointer(0) end
.get_binary_len_direct(mongocrypt_binary_t)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 185
def self.get_binary_len_direct(mongocrypt_binary_t) mongocrypt_binary_t.get_uint32(FFI::NativeType::POINTER.size) end
.init(handle)
Initialize the Mongo::Crypt::Handle object
# File 'lib/mongo/crypt/binding.rb', line 407
def self.init(handle) check_status(handle) do mongocrypt_init(handle.ref) end end
.kms_ctx_bytes_needed(kms_context) ⇒ Integer
Get the number of bytes needed by the KmsContext
.
# File 'lib/mongo/crypt/binding.rb', line 1063
def self.kms_ctx_bytes_needed(kms_context) mongocrypt_kms_ctx_bytes_needed(kms_context.kms_ctx_p) end
.kms_ctx_endpoint(kms_context) ⇒ String
| nil
Get the hostname with which to connect over TLS to get information about the AWS master key.
# File 'lib/mongo/crypt/binding.rb', line 1039
def self.kms_ctx_endpoint(kms_context) ptr = FFI::MemoryPointer.new(:pointer, 1) check_kms_ctx_status(kms_context) do mongocrypt_kms_ctx_endpoint(kms_context.kms_ctx_p, ptr) end str_ptr = ptr.read_pointer str_ptr.null? ? nil : str_ptr.read_string.force_encoding('UTF-8') end
.kms_ctx_fail(kms_context) ⇒ true
, false
Check whether the last failed request for the KMS
context may be retried.
# File 'lib/mongo/crypt/binding.rb', line 1148
def self.kms_ctx_fail(kms_context) mongocrypt_kms_ctx_fail(kms_context.kms_ctx_p) end
.kms_ctx_feed(kms_context, bytes)
Feed replies from the KMS
back to libmongocrypt.
# File 'lib/mongo/crypt/binding.rb', line 1083
def self.kms_ctx_feed(kms_context, bytes) check_kms_ctx_status(kms_context) do Binary.wrap_string(bytes) do |bytes_p| mongocrypt_kms_ctx_feed(kms_context.kms_ctx_p, bytes_p) end end end
.kms_ctx_get_kms_provider(kms_context)
# File 'lib/mongo/crypt/binding.rb', line 970
def self.kms_ctx_get_kms_provider(kms_context) len_ptr = FFI::MemoryPointer.new(:uint32, 1) provider = mongocrypt_kms_ctx_get_kms_provider( kms_context.kms_ctx_p, len_ptr ) if len_ptr.nil? nil else len = if BSON::Environment.jruby? # JRuby FFI implementation does not have `read(type)` method, but it # has this `get_uint32`. len_ptr.get_uint32 else # For MRI we use a documented `read` method - https://www.rubydoc.info/github/ffi/ffi/FFI%2FPointer:read len_ptr.read(:uint32) end provider.read_string(len).to_sym end end
.kms_ctx_message(kms_context) ⇒ String
Get the HTTP message needed to fetch the AWS KMS master key from a KmsContext
object.
# File 'lib/mongo/crypt/binding.rb', line 1010
def self. (kms_context) binary = Binary.new check_kms_ctx_status(kms_context) do (kms_context.kms_ctx_p, binary.ref) end return binary.to_s end
.kms_ctx_setopt_retry_kms(handle, value) ⇒ true
, fale
Enable or disable KMS
retry behavior.
# File 'lib/mongo/crypt/binding.rb', line 1167
def self.kms_ctx_setopt_retry_kms(handle, value) mongocrypt_setopt_retry_kms(handle.ref, value) end
.kms_ctx_usleep(kms_context) ⇒ Integer
[ GitHub ]
# File 'lib/mongo/crypt/binding.rb', line 1131
def self.kms_ctx_usleep(kms_context) mongocrypt_kms_ctx_usleep(kms_context.kms_ctx_p) end
.mongocrypt_binary_data(binary) ⇒ FFI::Pointer
Get the pointer to the underlying data for the mongocrypt_binary_t.
# File 'lib/mongo/crypt/binding.rb', line 171
attach_function :mongocrypt_binary_data, [:pointer], :pointer
.mongocrypt_binary_destroy(binary) ⇒ nil
Destroy the mongocrypt_binary_t object.
# File 'lib/mongo/crypt/binding.rb', line 195
attach_function :mongocrypt_binary_destroy, [:pointer], :void
.mongocrypt_binary_len(binary) ⇒ Integer
Get the length of the underlying data array.
# File 'lib/mongo/crypt/binding.rb', line 179
attach_function :mongocrypt_binary_len, [:pointer], :int
.mongocrypt_binary_new ⇒ FFI::Pointer
Creates a new mongocrypt_binary_t object (a non-owning view of a byte
array).
# File 'lib/mongo/crypt/binding.rb', line 147
attach_function :mongocrypt_binary_new, [], :pointer
.mongocrypt_binary_new_from_data(data, len) ⇒ FFI::Pointer
Create a new mongocrypt_binary_t object that maintains a pointer to
the specified byte array.
# File 'lib/mongo/crypt/binding.rb', line 159
attach_function( :mongocrypt_binary_new_from_data, [:pointer, :int], :pointer )
.mongocrypt_ctx_datakey_init(ctx, filter)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 618
attach_function :mongocrypt_ctx_datakey_init, [:pointer], :bool
.mongocrypt_ctx_decrypt_init(ctx, doc) ⇒ Boolean
Initializes the ctx for auto-decryption.
# File 'lib/mongo/crypt/binding.rb', line 778
attach_function :mongocrypt_ctx_decrypt_init, [:pointer, :pointer], :bool
.mongocrypt_ctx_destroy(ctx) ⇒ nil
Destroy the reference to the mongocrypt_ctx_t object.
# File 'lib/mongo/crypt/binding.rb', line 1228
attach_function :mongocrypt_ctx_destroy, [:pointer], :void
.mongocrypt_ctx_encrypt_init(ctx, db, db_len, cmd) ⇒ Boolean
This method expects the passed-in BSON to be in the format: { “v”: BSON value to decrypt }.
Initializes the ctx for auto-encryption.
# File 'lib/mongo/crypt/binding.rb', line 678
attach_function( :mongocrypt_ctx_encrypt_init, [:pointer, :string, :int, :pointer], :bool )
.mongocrypt_ctx_explicit_decrypt_init(ctx, msg) ⇒ Boolean
Initializes the ctx for explicit decryption.
# File 'lib/mongo/crypt/binding.rb', line 804
attach_function( :mongocrypt_ctx_explicit_decrypt_init, [:pointer, :pointer], :bool )
.mongocrypt_ctx_explicit_encrypt_init(ctx, msg) ⇒ Boolean
Before calling this method, set a key_id, key_alt_name (optional), and encryption algorithm using the following methods: mongocrypt_ctx_setopt_key_id, mongocrypt_ctx_setopt_key_alt_name, and mongocrypt_ctx_setopt_algorithm.
Initializes the ctx for explicit expression encryption.
# File 'lib/mongo/crypt/binding.rb', line 714
attach_function( :mongocrypt_ctx_explicit_encrypt_init, [:pointer, :pointer], :bool )
.mongocrypt_ctx_finalize(ctx, op_bson) ⇒ Boolean
Perform the final encryption or decryption and return a BSON document.
# File 'lib/mongo/crypt/binding.rb', line 1201
attach_function :mongocrypt_ctx_finalize, [:pointer, :pointer], :void
.mongocrypt_ctx_mongo_done(ctx) ⇒ Boolean
Indicate to libmongocrypt that the driver is done feeding replies.
# File 'lib/mongo/crypt/binding.rb', line 913
attach_function :mongocrypt_ctx_mongo_done, [:pointer], :bool
.mongocrypt_ctx_mongo_feed(ctx, reply) ⇒ Boolean
Feed a BSON reply to libmongocrypt.
# File 'lib/mongo/crypt/binding.rb', line 889
attach_function :mongocrypt_ctx_mongo_feed, [:pointer, :pointer], :bool
.mongocrypt_ctx_mongo_next_kms_ctx(ctx) ⇒ FFI::Pointer
Return a pointer to a mongocrypt_kms_ctx_t object or NULL.
# File 'lib/mongo/crypt/binding.rb', line 921
attach_function :mongocrypt_ctx_next_kms_ctx, [:pointer], :pointer
.mongocrypt_ctx_mongo_op(ctx, op_bson) ⇒ Boolean
Get a BSON operation for the driver to run against the MongoDB
collection, the key vault database, or mongocryptd.
# File 'lib/mongo/crypt/binding.rb', line 857
attach_function :mongocrypt_ctx_mongo_op, [:pointer, :pointer], :bool
.mongocrypt_ctx_new(crypt) ⇒ FFI::Pointer
Create a new mongocrypt_ctx_t object (a wrapper for the libmongocrypt
state machine).
# File 'lib/mongo/crypt/binding.rb', line 438
attach_function :mongocrypt_ctx_new, [:pointer], :pointer
.mongocrypt_ctx_provide_kms_providers(ctx, kms_providers)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 1670
attach_function( :mongocrypt_ctx_provide_kms_providers, [ :pointer, :pointer ], :bool )
.mongocrypt_ctx_setopt_algorithm(ctx, algorithm, len) ⇒ Boolean
Do not initialize ctx before calling this method.
Set the algorithm used for explicit encryption.
# File 'lib/mongo/crypt/binding.rb', line 555
attach_function( :mongocrypt_ctx_setopt_algorithm, [:pointer, :string, :int], :bool )
.mongocrypt_ctx_setopt_algorithm_range(ctx, opts)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 1776
attach_function( :mongocrypt_ctx_setopt_algorithm_range, [ :pointer, :pointer ], :bool )
.mongocrypt_ctx_setopt_contention_factor(ctx, contention_factor)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 1741
attach_function( :mongocrypt_ctx_setopt_contention_factor, [ :pointer, :int64 ], :bool )
.mongocrypt_ctx_setopt_key_alt_name(ctx, binary) ⇒ Boolean
Do not initialize ctx before calling this method.
When creating a data key, set an alternate name on that key. When
performing explicit encryption, which data key to use for
encryption based on its keyAltName field.
# File 'lib/mongo/crypt/binding.rb', line 487
attach_function( :mongocrypt_ctx_setopt_key_alt_name, [:pointer, :pointer], :bool )
.mongocrypt_ctx_setopt_key_encryption_key(ctx) ⇒ Boolean
Do not initialize ctx before calling this method.
Set key encryption key document for creating a data key.
# File 'lib/mongo/crypt/binding.rb', line 585
attach_function( :mongocrypt_ctx_setopt_key_encryption_key, [:pointer, :pointer], :bool )
.mongocrypt_ctx_setopt_key_id(ctx, key_id) ⇒ Boolean
Do not initialize ctx before calling this method.
Set the key id used for explicit encryption.
# File 'lib/mongo/crypt/binding.rb', line 459
attach_function :mongocrypt_ctx_setopt_key_id, [:pointer, :pointer], :bool
.mongocrypt_ctx_setopt_key_material(ctx, binary) ⇒ Boolean
Do not initialize ctx before calling this method.
When creating a data key, set a custom key material to use for
encrypting data.
# File 'lib/mongo/crypt/binding.rb', line 522
attach_function( :mongocrypt_ctx_setopt_key_material, [:pointer, :pointer], :bool )
.mongocrypt_ctx_setopt_query_type(ctx, mongocrypt_query_type)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 1708
attach_function( :mongocrypt_ctx_setopt_query_type, [ :pointer, :string, :int ], :bool )
.mongocrypt_ctx_state(ctx) ⇒ Symbol
Get the current state of the ctx.
# File 'lib/mongo/crypt/binding.rb', line 845
attach_function :mongocrypt_ctx_state, [:pointer], :mongocrypt_ctx_state
.mongocrypt_ctx_status(ctx, status) ⇒ Boolean
Set the status information from the mongocrypt_ctx_t object on the
mongocrypt_status_t object.
# File 'lib/mongo/crypt/binding.rb', line 448
attach_function :mongocrypt_ctx_status, [:pointer, :pointer], :bool
.mongocrypt_destroy(crypt) ⇒ nil
Destroy the reference the mongocrypt_t object.
# File 'lib/mongo/crypt/binding.rb', line 429
attach_function :mongocrypt_destroy, [:pointer], :void
.mongocrypt_init(crypt) ⇒ Boolean
Initialize the mongocrypt_t object.
# File 'lib/mongo/crypt/binding.rb', line 400
attach_function :mongocrypt_init, [:pointer], :bool
.mongocrypt_kms_ctx_bytes_needed(kms) ⇒ Integer
Get the number of bytes needed by the KMS
context.
# File 'lib/mongo/crypt/binding.rb', line 1056
attach_function :mongocrypt_kms_ctx_bytes_needed, [:pointer], :int
.mongocrypt_kms_ctx_done(ctx) ⇒ Boolean
Indicate to libmongocrypt that it will receive no more replies from
mongocrypt_kms_ctx_t objects.
# File 'lib/mongo/crypt/binding.rb', line 1179
attach_function :mongocrypt_ctx_kms_done, [:pointer], :bool
.mongocrypt_kms_ctx_endpoint(kms, endpoint) ⇒ Boolean
Get the hostname with which to connect over TLS to get information about
the AWS master key.
# File 'lib/mongo/crypt/binding.rb', line 1029
attach_function :mongocrypt_kms_ctx_endpoint, [:pointer, :pointer], :bool
.mongocrypt_kms_ctx_fail(ctx)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 1142
attach_function :mongocrypt_kms_ctx_fail, [:pointer], :bool
.mongocrypt_kms_ctx_feed(kms, bytes) ⇒ Boolean
Feed replies from the KMS
back to libmongocrypt.
# File 'lib/mongo/crypt/binding.rb', line 1075
attach_function :mongocrypt_kms_ctx_feed, [:pointer, :pointer], :bool
.mongocrypt_kms_ctx_get_kms_provider(crypt, kms_providers)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 955
attach_function( :mongocrypt_kms_ctx_get_kms_provider, [:pointer, :pointer], :pointer )
.mongocrypt_kms_ctx_message(kms, msg) ⇒ Boolean
Get the message needed to fetch the AWS KMS master key.
# File 'lib/mongo/crypt/binding.rb', line 1000
attach_function :, [:pointer, :pointer], :bool
.mongocrypt_kms_ctx_status(kms, status) ⇒ Boolean
Write status information about the mongocrypt_kms_ctx_t object
to the mongocrypt_status_t object.
# File 'lib/mongo/crypt/binding.rb', line 1099
attach_function :mongocrypt_kms_ctx_status, [:pointer, :pointer], :bool
.mongocrypt_kms_ctx_usleep(ctx) ⇒ int64
Indicates how long to sleep before sending KMS
request.
# File 'lib/mongo/crypt/binding.rb', line 1123
attach_function :mongocrypt_kms_ctx_usleep, [:pointer], :int64
.mongocrypt_setopt_aes_256_ctr(crypt, aes_256_ctr_encrypt, aes_256_ctr_decrypt, ctx) ⇒ Boolean
Set a crypto hook for the AES256-CTR operations.
# File 'lib/mongo/crypt/binding.rb', line 1487
attach_function( :mongocrypt_setopt_aes_256_ctr, [ :pointer, :mongocrypt_crypto_fn, :mongocrypt_crypto_fn, :pointer ], :bool )
.mongocrypt_setopt_bypass_query_analysis(crypt)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 1463
attach_function(:mongocrypt_setopt_bypass_query_analysis, [:pointer], :void)
.mongocrypt_setopt_crypto_hook_sign_rsaes_pkcs1_v1_5(crypt, sign_rsaes_pkcs1_v1_5, ctx = nil) ⇒ Boolean
Set a crypto hook for the RSASSA-PKCS1-v1_5 algorithm with a SHA-256 hash.
# File 'lib/mongo/crypt/binding.rb', line 1380
attach_function( :mongocrypt_setopt_crypto_hook_sign_rsaes_pkcs1_v1_5, [ :pointer, :mongocrypt_hmac_fn, :pointer ], :bool )
.mongocrypt_setopt_crypto_hooks(crypt, aes_enc_fn, aes_dec_fn, random_fn, sha_512_fn, sha_256_fn, hash_fn, ctx = nil) ⇒ Boolean
Set crypto hooks on the provided mongocrypt object.
# File 'lib/mongo/crypt/binding.rb', line 1333
attach_function( :mongocrypt_setopt_crypto_hooks, [ :pointer, :mongocrypt_crypto_fn, :mongocrypt_crypto_fn, :mongocrypt_random_fn, :mongocrypt_hmac_fn, :mongocrypt_hmac_fn, :mongocrypt_hash_fn, :pointer ], :bool )
.mongocrypt_setopt_encrypted_field_config_map(crypt, efc_map)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 1422
attach_function( :mongocrypt_setopt_encrypted_field_config_map, [ :pointer, :pointer ], :bool )
.mongocrypt_setopt_kms_providers(crypt, kms_providers)
Do not initialize ctx before calling this method.
Configure KMS providers with a BSON document.
# File 'lib/mongo/crypt/binding.rb', line 344
attach_function( :mongocrypt_setopt_kms_providers, [:pointer, :pointer], :bool )
.mongocrypt_setopt_log_handler(crypt, log_fn, log_ctx = nil) ⇒ Boolean
Set the handler on the mongocrypt_t object to be called every time
libmongocrypt logs a .
# File 'lib/mongo/crypt/binding.rb', line 315
attach_function( :mongocrypt_setopt_log_handler, [:pointer, :mongocrypt_log_fn_t, :pointer], :bool )
.mongocrypt_setopt_retry_kms(crypt, enable)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 1160
attach_function :mongocrypt_setopt_retry_kms, [:pointer, :bool], :bool
.mongocrypt_setopt_schema_map(crypt, schema_map) ⇒ Boolean
Sets a local schema map for encryption.
# File 'lib/mongo/crypt/binding.rb', line 375
attach_function :mongocrypt_setopt_schema_map, [:pointer, :pointer], :bool
.mongocrypt_setopt_use_need_kms_credentials_state(crypt)
[ GitHub ]# File 'lib/mongo/crypt/binding.rb', line 1633
attach_function( :mongocrypt_setopt_use_need_kms_credentials_state, [ :pointer ], :void )
.mongocrypt_status(crypt, status) ⇒ Boolean
Set the status information from the mongocrypt_t object on the
mongocrypt_status_t object.
# File 'lib/mongo/crypt/binding.rb', line 421
attach_function :mongocrypt_status, [:pointer, :pointer], :bool
.mongocrypt_status_code(status) ⇒ Integer
Return the status error code.
# File 'lib/mongo/crypt/binding.rb', line 243
attach_function :mongocrypt_status_code, [:pointer], :int
.mongocrypt_status_destroy(status) ⇒ nil
Destroys the reference to the mongocrypt_status_t object.
# File 'lib/mongo/crypt/binding.rb', line 269
attach_function :mongocrypt_status_destroy, [:pointer], :void
.mongocrypt_status_message(status, len = nil) ⇒ String
Returns the status message.
# File 'lib/mongo/crypt/binding.rb', line 253
attach_function :, [:pointer, :pointer], :string
.mongocrypt_status_new ⇒ FFI::Pointer
Create a new mongocrypt_status_t object.
# File 'lib/mongo/crypt/binding.rb', line 209
attach_function :mongocrypt_status_new, [], :pointer
.mongocrypt_status_ok(status) ⇒ Boolean
Returns whether the status is ok or an error.
# File 'lib/mongo/crypt/binding.rb', line 261
attach_function :mongocrypt_status_ok, [:pointer], :bool
.mongocrypt_status_set(status, type, code, message, len) ⇒ nil
Set a message, type, and code on an existing status.
# File 'lib/mongo/crypt/binding.rb', line 223
attach_function( :mongocrypt_status_set, [:pointer, :status_type, :int, :string, :int], :void )
.mongocrypt_status_type(status) ⇒ Symbol
Indicates the status type.
# File 'lib/mongo/crypt/binding.rb', line 235
attach_function :mongocrypt_status_type, [:pointer], :status_type
.mongocrypt_version(len) ⇒ String
Returns the version string of the libmongocrypt library.
# File 'lib/mongo/crypt/binding.rb', line 95
attach_function :mongocrypt_version, [:pointer], :string
.ongocrypt_new ⇒ FFI::Pointer
Creates a new mongocrypt_t object.
# File 'lib/mongo/crypt/binding.rb', line 303
attach_function :mongocrypt_new, [], :pointer
.parse_version(version) ⇒ Gem::Version
Given a string representing a version number, parses it into a Gem::Version object. This handles the case where the string is not in a format supported by Gem::Version by doing some custom parsing.
# File 'lib/mongo/crypt/binding.rb', line 108
def self.parse_version(version) Gem::Version.new(version) rescue ArgumentError match = version.match(/\A(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)?(-[A-Za-z\+\d]+)?\z/) raise ArgumentError.new("Malformed version number string #{version}") if match.nil? Gem::Version.new( [ match[:major], match[:minor], match[:patch] ].join('.') ) end
.setopt_aes_256_ctr(handle, aes_ctr_encrypt_cb, aes_ctr_decrypt_cb)
Set a crypto hook for the AES256-CTR operations.
# File 'lib/mongo/crypt/binding.rb', line 1505
def self.setopt_aes_256_ctr(handle, aes_ctr_encrypt_cb, aes_ctr_decrypt_cb) check_status(handle) do mongocrypt_setopt_aes_256_ctr(handle.ref, aes_ctr_encrypt_cb, aes_ctr_decrypt_cb, nil ) end end
.setopt_bypass_query_analysis(handle)
Opt-into skipping query analysis.
If opted in:
-
The csfle shared library will not attempt to be loaded.
-
A mongocrypt_ctx_t will never enter the MONGOCRYPT_CTX_NEED_MARKINGS state.
# File 'lib/mongo/crypt/binding.rb', line 1472
def self.setopt_bypass_query_analysis(handle) mongocrypt_setopt_bypass_query_analysis(handle.ref) end
.setopt_crypto_hook_sign_rsaes_pkcs1_v1_5(handle, rsaes_pkcs_signature_cb)
Set a crypto hook for the RSASSA-PKCS1-v1_5 algorithm with
a SHA-256 hash oh the Handle.
# File 'lib/mongo/crypt/binding.rb', line 1397
def self.setopt_crypto_hook_sign_rsaes_pkcs1_v1_5( handle, rsaes_pkcs_signature_cb ) check_status(handle) do mongocrypt_setopt_crypto_hook_sign_rsaes_pkcs1_v1_5( handle.ref, rsaes_pkcs_signature_cb, nil ) end end
.setopt_crypto_hooks(handle, aes_encrypt_cb, aes_decrypt_cb, random_cb, hmac_sha_512_cb, hmac_sha_256_cb, hmac_hash_cb)
Set crypto callbacks on the Handle
# File 'lib/mongo/crypt/binding.rb', line 1359
def self.setopt_crypto_hooks(handle, aes_encrypt_cb, aes_decrypt_cb, random_cb, hmac_sha_512_cb, hmac_sha_256_cb, hmac_hash_cb ) check_status(handle) do mongocrypt_setopt_crypto_hooks(handle.ref, aes_encrypt_cb, aes_decrypt_cb, random_cb, hmac_sha_512_cb, hmac_sha_256_cb, hmac_hash_cb, nil ) end end
.setopt_encrypted_field_config_map(handle, efc_map)
Set a local EncryptedFieldConfigMap for encryption.
# File 'lib/mongo/crypt/binding.rb', line 1440
def self.setopt_encrypted_field_config_map(handle, efc_map) validate_document(efc_map) data = efc_map.to_bson.to_s Binary.wrap_string(data) do |data_p| check_status(handle) do mongocrypt_setopt_encrypted_field_config_map( handle.ref, data_p ) end end end
.setopt_kms_providers(handle, kms_providers)
Set KMS providers options on the Mongo::Crypt::Handle object
# File 'lib/mongo/crypt/binding.rb', line 357
def self.setopt_kms_providers(handle, kms_providers) validate_document(kms_providers) data = kms_providers.to_bson.to_s Binary.wrap_string(data) do |data_p| check_status(handle) do mongocrypt_setopt_kms_providers(handle.ref, data_p) end end end
.setopt_log_handler(handle, log_callback)
Set the logger callback function on the Mongo::Crypt::Handle object
# File 'lib/mongo/crypt/binding.rb', line 327
def self.setopt_log_handler(handle, log_callback) check_status(handle) do mongocrypt_setopt_log_handler(handle, log_callback, nil) end end
.setopt_schema_map(handle, schema_map_doc)
Set schema map on the Mongo::Crypt::Handle object
# File 'lib/mongo/crypt/binding.rb', line 384
def self.setopt_schema_map(handle, schema_map_doc) validate_document(schema_map_doc) data = schema_map_doc.to_bson.to_s Binary.wrap_string(data) do |data_p| check_status(handle) do mongocrypt_setopt_schema_map(handle.ref, data_p) end end end
.setopt_use_need_kms_credentials_state(handle)
Opt-into handling the MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS state.
If set, before entering the MONGOCRYPT_CTX_NEED_KMS state, contexts may enter the MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS state and then wait for credentials to be supplied through .mongocrypt_ctx_provide_kms_providers.
A context will only enter MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS if an empty document was set for a KMS
provider in .mongocrypt_setopt_kms_providers.
# File 'lib/mongo/crypt/binding.rb', line 1651
def self.setopt_use_need_kms_credentials_state(handle) mongocrypt_setopt_use_need_kms_credentials_state(handle.ref) end
.validate_document(data)
All BSON::Document instances are also Hash instances
Checks that the specified data is a Hash before serializing it to BSON to prevent errors from libmongocrypt
# File 'lib/mongo/crypt/binding.rb', line 1844
def self.validate_document(data) return if data.is_a?(Hash) if data.nil? = "Attempted to pass nil data to libmongocrypt. " + "Data must be a Hash" else = "Attempted to pass invalid data to libmongocrypt: #{data} " + "Data must be a Hash" end raise Error::CryptError.new( ) end
.validate_version(lmc_version)
Validates if provided version of libmongocrypt is valid, i.e. equal or greater than minimum required version. Raises a LoadError if not.
# File 'lib/mongo/crypt/binding.rb', line 131
def self.validate_version(lmc_version) if (actual_version = parse_version(lmc_version)) < MIN_LIBMONGOCRYPT_VERSION raise LoadError, "libmongocrypt version #{MIN_LIBMONGOCRYPT_VERSION} or above is required, " + "but version #{actual_version} was found." end end
Instance Method Details
#mongocrypt_crypto_fn(ctx, key, iv, input, output, status) ⇒ Bool
This defines a method signature for an FFI callback; it is not an instance method on the Binding
class.
A callback to a function that performs AES encryption or decryption.
# File 'lib/mongo/crypt/binding.rb', line 1251
callback( :mongocrypt_crypto_fn, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :bool )
#mongocrypt_hash_fn(ctx, input, output, status) ⇒ Bool
This defines a method signature for an FFI callback; it is not an instance method on the Binding
class.
A callback to a SHA-256 hash function.
# File 'lib/mongo/crypt/binding.rb', line 1299
callback :mongocrypt_hash_fn, [:pointer, :pointer, :pointer, :pointer], :bool
#mongocrypt_hmac_fn(ctx, key, input, output, status) ⇒ Bool
This defines a method signature for an FFI callback; it is not an instance method on the Binding
class.
A callback to a function that performs HMAC SHA-512 or SHA-256.
# File 'lib/mongo/crypt/binding.rb', line 1276
callback( :mongocrypt_hmac_fn, [:pointer, :pointer, :pointer, :pointer, :pointer], :bool )
#mongocrypt_log_fn_t(level, message, len, ctx) ⇒ nil
This defines a method signature for an FFI callback; it is not an instance method on the Binding
class.
A callback to the mongocrypt log function. Set a custom log callback
with the mongocrypt_setopt_log_handler method
# File 'lib/mongo/crypt/binding.rb', line 296
callback :mongocrypt_log_fn_t, [:log_level, :string, :int, :pointer], :void
#mongocrypt_random_fn(ctx, output, count, status) ⇒ Bool
This defines a method signature for an FFI callback; it is not an instance method on the Binding
class.
A callback to a crypto secure random function.
# File 'lib/mongo/crypt/binding.rb', line 1317
callback :mongocrypt_random_fn, [:pointer, :pointer, :int, :pointer], :bool