Class: Mongo::Crypt::Binding Private

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/mongo/crypt/binding.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.

A Ruby binding for the libmongocrypt C library

API:

  • private

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check_ctx_status(context) ⇒ 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.

Raise a Mongo::Error::CryptError based on the status of the underlying mongocrypt_ctx_t object.

Returns:

  • Always nil.

API:

  • private



1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
# File 'lib/mongo/crypt/binding.rb', line 1194

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) ⇒ 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.

If the provided block returns false, raise a CryptError with the status information from the provided KmsContext object.

Parameters:

Raises:

  • If the provided block returns false

API:

  • private



969
970
971
972
973
974
975
976
# File 'lib/mongo/crypt/binding.rb', line 969

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
  end
end

.check_status(handle) ⇒ 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.

Raise a Mongo::Error::CryptError based on the status of the underlying mongocrypt_t object.

Returns:

  • Always nil.

API:

  • private



1181
1182
1183
1184
1185
1186
1187
1188
# File 'lib/mongo/crypt/binding.rb', line 1181

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) ⇒ 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.

Initialize the Context to create a data key

Parameters:

Raises:

  • If initialization fails

API:

  • private



608
609
610
611
612
# File 'lib/mongo/crypt/binding.rb', line 608

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) ⇒ 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.

Initialize the Context for auto-decryption

Parameters:

  • A BSON document to decrypt

Raises:

  • If initialization fails

API:

  • private



701
702
703
704
705
706
707
708
709
# File 'lib/mongo/crypt/binding.rb', line 701

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) ⇒ 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.

Initialize the Context for auto-encryption

Parameters:

  • The name of the database against which the encrypted command is being performed

  • The command to be encrypted

Raises:

  • If initialization fails

API:

  • private



641
642
643
644
645
646
647
648
649
# File 'lib/mongo/crypt/binding.rb', line 641

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) ⇒ 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.

Initialize the Context for explicit decryption

Parameters:

  • A BSON document to decrypt

Raises:

  • If initialization fails

API:

  • private



731
732
733
734
735
736
737
738
739
# File 'lib/mongo/crypt/binding.rb', line 731

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_init(context, doc) ⇒ 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.

Initialize the Context for explicit encryption

Parameters:

  • A BSON document to encrypt

Raises:

  • If initialization fails

API:

  • private



675
676
677
678
679
680
681
682
683
# File 'lib/mongo/crypt/binding.rb', line 675

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) ⇒ 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.

Finalize the state machine represented by the Context

Parameters:

Raises:

  • If the state machine is not successfully finalized

API:

  • private



1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
# File 'lib/mongo/crypt/binding.rb', line 1015

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) ⇒ 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.

Indicate to libmongocrypt that it will receive no more KMS replies.

Parameters:

Raises:

  • If the operation is unsuccessful

API:

  • private



992
993
994
995
996
# File 'lib/mongo/crypt/binding.rb', line 992

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) ⇒ 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.

Feed a response from the driver back to libmongocrypt

Parameters:

  • The document representing the response

Raises:

  • If the response is not fed successfully

API:

  • private



811
812
813
814
815
816
817
818
819
# File 'lib/mongo/crypt/binding.rb', line 811

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

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.

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).

Parameters:

Returns:

  • The operation that the driver must perform

Raises:

  • If there is an error getting the operation

API:

  • private



782
783
784
785
786
787
788
789
790
791
792
793
# File 'lib/mongo/crypt/binding.rb', line 782

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

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.

Return a new KmsContext object needed by a Context object.

Parameters:

Returns:

  • The KmsContext needed to fetch an AWS master key or nil, if no KmsContext is needed

API:

  • private



843
844
845
846
847
848
849
850
851
# File 'lib/mongo/crypt/binding.rb', line 843

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_setopt_algorithm(context, name) ⇒ 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.

Set the algorithm on the context

Parameters:

  • The algorithm name. Valid values are:

    • “AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic”

    • “AEAD_AES_256_CBC_HMAC_SHA_512-Random”

Raises:

  • If the operation failed

API:

  • private



493
494
495
496
497
# File 'lib/mongo/crypt/binding.rb', line 493

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_key_alt_names(context, key_alt_names) ⇒ 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.

Set multiple alternate key names on data key creation

Parameters:

  • A DataKeyContext

  • An array of alternate key names as strings

Raises:

  • If any of the alternate names are not valid UTF8 strings

API:

  • private



456
457
458
459
460
461
462
463
464
465
466
# File 'lib/mongo/crypt/binding.rb', line 456

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_id(context, key_id) ⇒ 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.

Sets the key id option on an explicit encryption context.

Parameters:

  • Explicit encryption context

  • The key id

Raises:

  • If the operation failed

API:

  • private



423
424
425
426
427
428
429
# File 'lib/mongo/crypt/binding.rb', line 423

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_master_key_aws(context, region, arn) ⇒ 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.

Configure the Context object to take a master key from AWS

Parameters:

  • The AWS region (e.g. “us-east-2”)

  • The master key Amazon Resource Name

Raises:

  • If the operation failed

API:

  • private



524
525
526
527
528
529
530
531
532
533
534
# File 'lib/mongo/crypt/binding.rb', line 524

def self.ctx_setopt_master_key_aws(context, region, arn)
  check_ctx_status(context) do
    mongocrypt_ctx_setopt_masterkey_aws(
      context.ctx_p,
      region,
      -1,
      arn,
      -1
    )
  end
end

.ctx_setopt_master_key_aws_endpoint(context, endpoint) ⇒ 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.

Configure the Context object to take a master key from AWS

Parameters:

  • The custom AWS master key endpoint

Raises:

  • If the operation failed

API:

  • private



557
558
559
560
561
562
563
564
565
# File 'lib/mongo/crypt/binding.rb', line 557

def self.ctx_setopt_master_key_aws_endpoint(context, endpoint)
  check_ctx_status(context) do
    mongocrypt_ctx_setopt_masterkey_aws_endpoint(
      context.ctx_p,
      endpoint,
      -1,
    )
  end
end

.ctx_setopt_master_key_local(context) ⇒ 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.

Tell the Context object to read the master key from local KMS options

Parameters:

Raises:

  • If the operation failed

API:

  • private



585
586
587
588
589
# File 'lib/mongo/crypt/binding.rb', line 585

def self.ctx_setopt_master_key_local(context)
  check_ctx_status(context) do
    mongocrypt_ctx_setopt_masterkey_local(context.ctx_p)
  end
end

.init(handle) ⇒ 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.

Initialize the Mongo::Crypt::Handle object

Parameters:

Raises:

  • If initialization fails

API:

  • private



363
364
365
366
367
# File 'lib/mongo/crypt/binding.rb', line 363

def self.init(handle)
  check_status(handle) do
    mongocrypt_init(handle.ref)
  end
end

.kms_ctx_bytes_needed(kms_context) ⇒ Integer

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.

Get the number of bytes needed by the KmsContext.

Parameters:

Returns:

  • The number of bytes needed

API:

  • private



925
926
927
# File 'lib/mongo/crypt/binding.rb', line 925

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

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.

Get the hostname with which to connect over TLS to get information about the AWS master key.

Parameters:

Returns:

  • The hostname, or nil if none exists

Raises:

  • If the response is not fed successfully

API:

  • private



901
902
903
904
905
906
907
908
909
910
# File 'lib/mongo/crypt/binding.rb', line 901

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_feed(kms_context, bytes) ⇒ 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.

Feed replies from the KMS back to libmongocrypt.

Parameters:

  • The data to feed to libmongocrypt

Raises:

  • If the response is not fed successfully

API:

  • private



945
946
947
948
949
950
951
# File 'lib/mongo/crypt/binding.rb', line 945

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_message(kms_context) ⇒ String

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.

Get the HTTP message needed to fetch the AWS KMS master key from a KmsContext object.

Parameters:

Returns:

  • The HTTP message

Raises:

  • If the response is not fed successfully

API:

  • private



872
873
874
875
876
877
878
879
880
# File 'lib/mongo/crypt/binding.rb', line 872

def self.kms_ctx_message(kms_context)
  binary = Binary.new

  check_kms_ctx_status(kms_context) do
    mongocrypt_kms_ctx_message(kms_context.kms_ctx_p, binary.ref)
  end

  return binary.to_s
end

.mongocrypt_binary_data(binary) ⇒ FFI::Pointer

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.

Get the pointer to the underlying data for the mongocrypt_binary_t.

Parameters:

  • A pointer to a mongocrypt_binary_t object.

Returns:

  • A pointer to the data array.

API:

  • private



102
# File 'lib/mongo/crypt/binding.rb', line 102

attach_function :mongocrypt_binary_data, [:pointer], :pointer

.mongocrypt_binary_destroy(binary) ⇒ 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.

Destroy the mongocrypt_binary_t object.

Parameters:

  • A pointer to a mongocrypt_binary_t object.

Returns:

  • Always nil.

API:

  • private



118
# File 'lib/mongo/crypt/binding.rb', line 118

attach_function :mongocrypt_binary_destroy, [:pointer], :void

.mongocrypt_binary_len(binary) ⇒ Integer

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.

Get the length of the underlying data array.

Parameters:

  • A pointer to a mongocrypt_binary_t object.

Returns:

  • The length of the data array.

API:

  • private



110
# File 'lib/mongo/crypt/binding.rb', line 110

attach_function :mongocrypt_binary_len, [:pointer], :int

.mongocrypt_binary_newFFI::Pointer

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.

Creates a new mongocrypt_binary_t object (a non-owning view of a byte

array).

Returns:

  • A pointer to the newly-created mongocrypt_binary_t object.

API:

  • private



78
# File 'lib/mongo/crypt/binding.rb', line 78

attach_function :mongocrypt_binary_new, [], :pointer

.mongocrypt_binary_new_from_data(data, len) ⇒ FFI::Pointer

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 mongocrypt_binary_t object that maintains a pointer to

the specified byte array.

Parameters:

  • A pointer to an array of bytes; the data is not copied and must outlive the mongocrypt_binary_t object.

  • The length of the array argument.

Returns:

  • A pointer to the newly-created mongocrypt_binary_t object.

API:

  • private



90
91
92
93
94
# File 'lib/mongo/crypt/binding.rb', line 90

attach_function(
  :mongocrypt_binary_new_from_data,
  [:pointer, :int],
  :pointer
)

.mongocrypt_ctx_datakey_init(ctx) ⇒ Boolean

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.

Note:

Before calling this method, master key options must be set. Set AWS master key by calling mongocrypt_ctx_setopt_masterkey_aws and mongocrypt_ctx_setopt_masterkey_aws_endpoint. Set local master key by calling mongocrypt_ctx_setopt_masterkey_local.

Initializes the ctx to create a data key.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

Returns:

  • Whether the initialization was successful.

API:

  • private



601
# File 'lib/mongo/crypt/binding.rb', line 601

attach_function :mongocrypt_ctx_datakey_init, [:pointer], :bool

.mongocrypt_ctx_decrypt_init(ctx, doc) ⇒ Boolean

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.

Initializes the ctx for auto-decryption.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

  • A pointer to a mongocrypt_binary_t object that references the document to be decrypted as a BSON binary string.

Returns:

  • Whether the initialization was successful.

API:

  • private



693
# File 'lib/mongo/crypt/binding.rb', line 693

attach_function :mongocrypt_ctx_decrypt_init, [:pointer, :pointer], :bool

.mongocrypt_ctx_destroy(ctx) ⇒ 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.

Destroy the reference to the mongocrypt_ctx_t object.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

Returns:

  • Always nil.

API:

  • private



1034
# File 'lib/mongo/crypt/binding.rb', line 1034

attach_function :mongocrypt_ctx_destroy, [:pointer], :void

.mongocrypt_ctx_encrypt_init(ctx, db, db_len, cmd) ⇒ Boolean

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.

Note:

This method expects the passed-in BSON to be in the format: { “v”: BSON value to decrypt }.

Initializes the ctx for auto-encryption.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

  • The database name.

  • The length of the database name argument (or -1 for a null-terminated string).

  • A pointer to a mongocrypt_binary_t object that references the database command as a binary string.

Returns:

  • Whether the initialization was successful.

API:

  • private



627
628
629
630
631
# File 'lib/mongo/crypt/binding.rb', line 627

attach_function(
  :mongocrypt_ctx_encrypt_init,
  [:pointer, :string, :int, :pointer],
  :bool
)

.mongocrypt_ctx_explicit_decrypt_init(ctx, msg) ⇒ Boolean

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.

Initializes the ctx for explicit decryption.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

  • A pointer to a mongocrypt_binary_t object that references the message to be decrypted as a BSON binary string.

Returns:

  • Whether the initialization was successful.

API:

  • private



719
720
721
722
723
# File 'lib/mongo/crypt/binding.rb', line 719

attach_function(
  :mongocrypt_ctx_explicit_decrypt_init,
  [:pointer, :pointer],
  :bool
)

.mongocrypt_ctx_explicit_encrypt_init(ctx, msg) ⇒ Boolean

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.

Note:

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 encryption.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

  • A pointer to a mongocrypt_binary_t object that references the message to be encrypted as a binary string.

Returns:

  • Whether the initialization was successful.

API:

  • private



663
664
665
666
667
# File 'lib/mongo/crypt/binding.rb', line 663

attach_function(
  :mongocrypt_ctx_explicit_encrypt_init,
  [:pointer, :pointer],
  :bool
)

.mongocrypt_ctx_finalize(ctx, op_bson) ⇒ Boolean

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.

Perform the final encryption or decryption and return a BSON document.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

  • (out param) A pointer to a mongocrypt_binary_t object that will have a reference to the final encrypted BSON document.

Returns:

  • A boolean indicating the success of the operation.

API:

  • private



1007
# File 'lib/mongo/crypt/binding.rb', line 1007

attach_function :mongocrypt_ctx_finalize, [:pointer, :pointer], :void

.mongocrypt_ctx_mongo_done(ctx) ⇒ Boolean

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.

Indicate to libmongocrypt that the driver is done feeding replies.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

Returns:

  • A boolean indicating the success of the operation.

API:

  • private



827
# File 'lib/mongo/crypt/binding.rb', line 827

attach_function :mongocrypt_ctx_mongo_done, [:pointer], :bool

.mongocrypt_ctx_mongo_feed(ctx, reply) ⇒ Boolean

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.

Feed a BSON reply to libmongocrypt.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

  • A mongocrypt_binary_t object that references the BSON reply to feed to libmongocrypt.

Returns:

  • A boolean indicating the success of the operation.

API:

  • private



803
# File 'lib/mongo/crypt/binding.rb', line 803

attach_function :mongocrypt_ctx_mongo_feed, [:pointer, :pointer], :bool

.mongocrypt_ctx_mongo_next_kms_ctx(ctx) ⇒ FFI::Pointer

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.

Return a pointer to a mongocrypt_kms_ctx_t object or NULL.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

Returns:

  • A pointer to a mongocrypt_kms_ctx_t object.

API:

  • private



835
# File 'lib/mongo/crypt/binding.rb', line 835

attach_function :mongocrypt_ctx_next_kms_ctx, [:pointer], :pointer

.mongocrypt_ctx_mongo_op(ctx, op_bson) ⇒ Boolean

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.

Get a BSON operation for the driver to run against the MongoDB

collection, the key vault database, or mongocryptd.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

  • (out param) A pointer to a mongocrypt_binary_t object that will have a reference to the BSON operation written to it by libmongocrypt.

Returns:

  • A boolean indicating the success of the operation.

API:

  • private



771
# File 'lib/mongo/crypt/binding.rb', line 771

attach_function :mongocrypt_ctx_mongo_op, [:pointer, :pointer], :bool

.mongocrypt_ctx_new(crypt) ⇒ FFI::Pointer

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 mongocrypt_ctx_t object (a wrapper for the libmongocrypt

state machine).

Parameters:

  • A pointer to a mongocrypt_t object.

Returns:

  • A new mongocrypt_ctx_t object.

API:

  • private



394
# File 'lib/mongo/crypt/binding.rb', line 394

attach_function :mongocrypt_ctx_new, [:pointer], :pointer

.mongocrypt_ctx_setopt_algorithm(ctx, algorithm, len) ⇒ Boolean

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.

Note:

Do not initialize ctx before calling this method.

Set the algorithm used for explicit encryption.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

  • The algorithm name. Valid values are:

    • “AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic”

    • “AEAD_AES_256_CBC_HMAC_SHA_512-Random”

  • The length of the algorithm string.

Returns:

  • Whether the option was successfully set.

API:

  • private



479
480
481
482
483
# File 'lib/mongo/crypt/binding.rb', line 479

attach_function(
  :mongocrypt_ctx_setopt_algorithm,
  [:pointer, :string, :int],
  :bool
)

.mongocrypt_ctx_setopt_key_alt_name(ctx, binary) ⇒ Boolean

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.

Note:

Do not initialize ctx before calling this method.

When creating a data key, set an alternate name on that key. When

performing explicit encryption, specifying which data key to use for
encryption based on its keyAltName field.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

  • A pointer to a mongocrypt_binary_t object that references a BSON document in the format { “keyAltName”: <BSON UTF8 value> }.

Returns:

  • Whether the alternative name was successfully set.

API:

  • private



443
444
445
446
447
# File 'lib/mongo/crypt/binding.rb', line 443

attach_function(
  :mongocrypt_ctx_setopt_key_alt_name,
  [:pointer, :pointer],
  :bool
)

.mongocrypt_ctx_setopt_key_id(ctx, key_id) ⇒ Boolean

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.

Note:

Do not initialize ctx before calling this method.

Set the key id used for explicit encryption.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

  • A pointer to a mongocrypt_binary_t object that references the 16-byte key-id.

Returns:

  • Whether the option was successfully set.

API:

  • private



415
# File 'lib/mongo/crypt/binding.rb', line 415

attach_function :mongocrypt_ctx_setopt_key_id, [:pointer, :pointer], :bool

.mongocrypt_ctx_setopt_masterkey_aws(ctx, region, region_len, arn, arn_len) ⇒ Boolean

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.

Configure the ctx to take a master key from AWS.

Parameters:

  • A pointer to a mongocrypt_ctx_object.

  • The AWS region.

  • The length of the region string (or -1 for a null-terminated string).

  • The Amazon Resource Name (ARN) of the mater key.

  • The length of the ARN (or -1 for a null-terminated string).

Returns:

  • Returns whether the option was set successfully.

API:

  • private



511
512
513
514
515
# File 'lib/mongo/crypt/binding.rb', line 511

attach_function(
  :mongocrypt_ctx_setopt_masterkey_aws,
  [:pointer, :string, :int, :string, :int],
  :bool
)

.mongocrypt_ctx_setopt_masterkey_aws_endpoint(ctx, endpoint, endpoint_len) ⇒ Boolean

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.

Set a custom endpoint at which to fetch the AWS master key

Parameters:

  • The custom endpoint.

  • The length of the endpoint string (or -1 for a null-terminated string).

Returns:

  • Returns whether the option was set successfully.

API:

  • private



545
546
547
548
549
# File 'lib/mongo/crypt/binding.rb', line 545

attach_function(
  :mongocrypt_ctx_setopt_masterkey_aws_endpoint,
  [:pointer, :string, :int],
  :bool
)

.mongocrypt_ctx_setopt_masterkey_local(ctx) ⇒ Boolean

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.

Note:

Do not initialize ctx before calling this method.

Set the ctx to take a local master key.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

Returns:

  • Whether the option was successfully set.

API:

  • private



574
575
576
577
578
# File 'lib/mongo/crypt/binding.rb', line 574

attach_function(
  :mongocrypt_ctx_setopt_masterkey_local,
  [:pointer],
  :bool
)

.mongocrypt_ctx_state(ctx) ⇒ Symbol

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.

Get the current state of the ctx.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

Returns:

  • The current state, will be one of the values defined by the mongocrypt_ctx_state enum.

API:

  • private



759
# File 'lib/mongo/crypt/binding.rb', line 759

attach_function :mongocrypt_ctx_state, [:pointer], :mongocrypt_ctx_state

.mongocrypt_ctx_status(ctx, status) ⇒ Boolean

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.

Set the status information from the mongocrypt_ctx_t object on the

mongocrypt_status_t object.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

  • A pointer to a mongocrypt_status_t object.

Returns:

  • Whether the status was successfully set.

API:

  • private



404
# File 'lib/mongo/crypt/binding.rb', line 404

attach_function :mongocrypt_ctx_status, [:pointer, :pointer], :bool

.mongocrypt_destroy(crypt) ⇒ 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.

Destroy the reference the mongocrypt_t object.

Parameters:

  • A pointer to a mongocrypt_t object.

Returns:

  • Always nil.

API:

  • private



385
# File 'lib/mongo/crypt/binding.rb', line 385

attach_function :mongocrypt_destroy, [:pointer], :void

.mongocrypt_init(crypt) ⇒ Boolean

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.

Initialize the mongocrypt_t object.

Parameters:

  • A pointer to a mongocrypt_t object.

Returns:

  • Returns whether the crypt was initialized successfully.

API:

  • private



356
# File 'lib/mongo/crypt/binding.rb', line 356

attach_function :mongocrypt_init, [:pointer], :bool

.mongocrypt_kms_ctx_bytes_needed(kms) ⇒ Integer

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.

Get the number of bytes needed by the KMS context.

Parameters:

  • The mongocrypt_kms_ctx_t object.

Returns:

  • The number of bytes needed.

API:

  • private



918
# File 'lib/mongo/crypt/binding.rb', line 918

attach_function :mongocrypt_kms_ctx_bytes_needed, [:pointer], :int

.mongocrypt_kms_ctx_done(ctx) ⇒ Boolean

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.

Indicate to libmongocrypt that it will receive no more replies from

mongocrypt_kms_ctx_t objects.

Parameters:

  • A pointer to a mongocrypt_ctx_t object.

Returns:

  • Whether the operation was successful.

API:

  • private



985
# File 'lib/mongo/crypt/binding.rb', line 985

attach_function :mongocrypt_ctx_kms_done, [:pointer], :bool

.mongocrypt_kms_ctx_endpoint(kms, endpoint) ⇒ Boolean

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.

Get the hostname with which to connect over TLS to get information about

the AWS master key.

Parameters:

  • A pointer to a mongocrypt_kms_ctx_t object.

  • (out param) A pointer to which the endpoint string will be written by libmongocrypt.

Returns:

  • Whether the operation was successful.

API:

  • private



891
# File 'lib/mongo/crypt/binding.rb', line 891

attach_function :mongocrypt_kms_ctx_endpoint, [:pointer, :pointer], :bool

.mongocrypt_kms_ctx_feed(kms, bytes) ⇒ Boolean

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.

Feed replies from the KMS back to libmongocrypt.

Parameters:

  • A pointer to the mongocrypt_kms_ctx_t object.

  • A pointer to a mongocrypt_binary_t object that references the response from the KMS.

Returns:

  • Whether the operation was successful.

API:

  • private



937
# File 'lib/mongo/crypt/binding.rb', line 937

attach_function :mongocrypt_kms_ctx_feed, [:pointer, :pointer], :bool

.mongocrypt_kms_ctx_message(kms, msg) ⇒ Boolean

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.

Get the message needed to fetch the AWS KMS master key.

Parameters:

  • Pointer to the mongocrypt_kms_ctx_t object

  • (outparam) Pointer to a mongocrypt_binary_t object that will have the location of the message written to it by libmongocrypt.

Returns:

  • Whether the operation is successful.

API:

  • private



862
# File 'lib/mongo/crypt/binding.rb', line 862

attach_function :mongocrypt_kms_ctx_message, [:pointer, :pointer], :bool

.mongocrypt_kms_ctx_status(kms, status) ⇒ Boolean

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.

Write status information about the mongocrypt_kms_ctx_t object

to the mongocrypt_status_t object.

Parameters:

  • A pointer to the mongocrypt_kms_ctx_t object.

  • A pointer to a mongocrypt_status_t object.

Returns:

  • Whether the operation was successful.

API:

  • private



961
# File 'lib/mongo/crypt/binding.rb', line 961

attach_function :mongocrypt_kms_ctx_status, [:pointer, :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

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.

Set crypto hooks on the provided mongocrypt object.

Parameters:

  • A pointer to a mongocrypt_t object.

  • An AES encryption method.

  • An AES decryption method.

  • A random method.

  • A HMAC SHA-512 method.

  • A HMAC SHA-256 method.

  • A SHA-256 hash method.

  • (defaults to: nil)

    An optional pointer to a context object that may have been set when hooks were enabled.

Returns:

  • Whether setting this option succeeded.

API:

  • private



1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
# File 'lib/mongo/crypt/binding.rb', line 1139

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_kms_provider_aws(crypt, aws_access_key_id, aws_access_key_id_len, aws_secret_access_key, aws_secret_access_key_len) ⇒ Boolean

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.

Configure mongocrypt_t object with AWS KMS provider options.

Parameters:

  • A pointer to a mongocrypt_t object.

  • The AWS access key id.

  • The length of the AWS access key string (or -1 for a null-terminated string).

  • The AWS secret access key.

  • The length of the AWS secret access key (or -1 for a null-terminated string).

Returns:

  • Returns whether the option was set successfully.

API:

  • private



268
269
270
271
272
# File 'lib/mongo/crypt/binding.rb', line 268

attach_function(
  :mongocrypt_setopt_kms_provider_aws,
  [:pointer, :string, :int, :string, :int],
  :bool
)

.mongocrypt_setopt_kms_provider_local(crypt, key) ⇒ Boolean

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.

Configure mongocrypt_t object to take local KSM provider options.

Parameters:

  • A pointer to a mongocrypt_t object.

  • A pointer to a mongocrypt_binary_t object that references the 96-byte local master key.

Returns:

  • Returns whether the option was set successfully.

API:

  • private



303
304
305
306
307
# File 'lib/mongo/crypt/binding.rb', line 303

attach_function(
  :mongocrypt_setopt_kms_provider_local,
  [:pointer, :pointer],
  :bool
)

.mongocrypt_setopt_log_handler(crypt, log_fn, log_ctx = nil) ⇒ Boolean

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.

Set the handler on the mongocrypt_t object to be called every time

libmongocrypt logs a message.

Parameters:

  • A pointer to a mongocrypt_t object.

  • A logging callback method.

  • (defaults to: nil)

    An optional pointer to a context to be passed into the log callback on every invocation.

Returns:

  • Whether setting the callback was successful.

API:

  • private



238
239
240
241
242
# File 'lib/mongo/crypt/binding.rb', line 238

attach_function(
  :mongocrypt_setopt_log_handler,
  [:pointer, :mongocrypt_log_fn_t, :pointer],
  :bool
)

.mongocrypt_setopt_schema_map(crypt, schema_map) ⇒ Boolean

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.

Sets a local schema map for encryption.

Parameters:

  • A pointer to a mongocrypt_t object.

  • A pointer to a mongocrypt_binary_t. object that references the schema map as a BSON binary string.

Returns:

  • Returns whether the option was set successfully.

API:

  • private



331
# File 'lib/mongo/crypt/binding.rb', line 331

attach_function :mongocrypt_setopt_schema_map, [:pointer, :pointer], :bool

.mongocrypt_status(crypt, status) ⇒ Boolean

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.

Set the status information from the mongocrypt_t object on the

mongocrypt_status_t object.

Parameters:

  • A pointer to a mongocrypt_t object.

  • A pointer to a mongocrypt_status_t object.

Returns:

  • Whether the status was successfully set.

API:

  • private



377
# File 'lib/mongo/crypt/binding.rb', line 377

attach_function :mongocrypt_status, [:pointer, :pointer], :bool

.mongocrypt_status_code(status) ⇒ Integer

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.

Return the status error code.

Parameters:

  • A pointer to a mongocrypt_status_t.

Returns:

  • The status code.

API:

  • private



166
# File 'lib/mongo/crypt/binding.rb', line 166

attach_function :mongocrypt_status_code, [:pointer], :int

.mongocrypt_status_destroy(status) ⇒ 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.

Destroys the reference to the mongocrypt_status_t object.

Parameters:

  • A pointer to a mongocrypt_status_t.

Returns:

  • Always nil.

API:

  • private



192
# File 'lib/mongo/crypt/binding.rb', line 192

attach_function :mongocrypt_status_destroy, [:pointer], :void

.mongocrypt_status_message(status, len = nil) ⇒ String

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.

Returns the status message.

Parameters:

  • A pointer to a mongocrypt_status_t.

  • (defaults to: nil)

    (out param) An optional pointer to a uint32, where the length of the retun string will be written.

Returns:

  • The status message.

API:

  • private



176
# File 'lib/mongo/crypt/binding.rb', line 176

attach_function :mongocrypt_status_message, [:pointer, :pointer], :string

.mongocrypt_status_newFFI::Pointer

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 mongocrypt_status_t object.

Returns:

  • A pointer to the new mongocrypt_status_ts.

API:

  • private



132
# File 'lib/mongo/crypt/binding.rb', line 132

attach_function :mongocrypt_status_new, [], :pointer

.mongocrypt_status_ok(status) ⇒ Boolean

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.

Returns whether the status is ok or an error.

Parameters:

  • A pointer to a mongocrypt_status_t.

Returns:

  • Whether the status is ok.

API:

  • private



184
# File 'lib/mongo/crypt/binding.rb', line 184

attach_function :mongocrypt_status_ok, [:pointer], :bool

.mongocrypt_status_set(status, type, code, message, len) ⇒ 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.

Set a message, type, and code on an existing status.

Parameters:

  • A pointer to a mongocrypt_status_t.

  • The status type; possible values are defined by the status_type enum.

  • The status code.

  • The status message.

  • The length of the message argument (or -1 for a null-terminated string).

Returns:

  • Always nil.

API:

  • private



146
147
148
149
150
# File 'lib/mongo/crypt/binding.rb', line 146

attach_function(
  :mongocrypt_status_set,
  [:pointer, :status_type, :int, :string, :int],
  :void
)

.mongocrypt_status_type(status) ⇒ Symbol

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.

Indicates the status type.

Parameters:

  • A pointer to a mongocrypt_status_t.

Returns:

  • The status type (as defined by the status_type enum).

API:

  • private



158
# File 'lib/mongo/crypt/binding.rb', line 158

attach_function :mongocrypt_status_type, [:pointer], :status_type

.mongocrypt_version(len) ⇒ String

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.

Returns the version string of the libmongocrypt library.

Parameters:

  • (out param) An optional pointer to a uint8 that will reference the length of the returned string.

Returns:

  • A version string for libmongocrypt.

API:

  • private



69
# File 'lib/mongo/crypt/binding.rb', line 69

attach_function :mongocrypt_version, [:pointer], :string

.ongocrypt_newFFI::Pointer

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.

Creates a new mongocrypt_t object.

Returns:

  • A pointer to a new mongocrypt_t object.

API:

  • private



226
# File 'lib/mongo/crypt/binding.rb', line 226

attach_function :mongocrypt_new, [], :pointer

.setopt_crypto_hooks(handle, aes_encrypt_cb, aes_decrypt_cb, random_cb, hmac_sha_512_cb, hmac_sha_256_cb, hmac_hash_cb) ⇒ 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.

Set crypto callbacks on the Handle

Parameters:

  • An AES encryption method

  • A AES decryption method

  • A method that returns a string of random bytes

  • A HMAC SHA-512 method

  • A HMAC SHA-256 method

  • A SHA-256 hash method

Raises:

  • If the callbacks aren’t set successfully

API:

  • private



1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
# File 'lib/mongo/crypt/binding.rb', line 1165

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_kms_provider_aws(handle, aws_access_key, aws_secret_access_key) ⇒ 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.

Configure the Handle object with AWS KMS provider options

Parameters:

  • The AWS access key

  • The AWS secret access key

Raises:

  • If the option is not set successfully

API:

  • private



281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/mongo/crypt/binding.rb', line 281

def self.setopt_kms_provider_aws(handle,
  aws_access_key, aws_secret_access_key
)
  check_status(handle) do
    mongocrypt_setopt_kms_provider_aws(
      handle.ref,
      aws_access_key,
      -1,
      aws_secret_access_key,
      -1
    )
  end
end

.setopt_kms_provider_local(handle, master_key) ⇒ 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.

Set local KMS provider options on the Mongo::Crypt::Handle object

Parameters:

  • The 96-byte local KMS master key

Raises:

  • If the option is not set successfully

API:

  • private



315
316
317
318
319
320
321
# File 'lib/mongo/crypt/binding.rb', line 315

def self.setopt_kms_provider_local(handle, master_key)
  Binary.wrap_string(master_key) do |master_key_p|
    check_status(handle) do
      mongocrypt_setopt_kms_provider_local(handle.ref, master_key_p)
    end
  end
end

.setopt_log_handler(handle, log_callback) ⇒ 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.

Set the logger callback function on the Mongo::Crypt::Handle object

Parameters:

Raises:

  • If the callback is not set successfully

API:

  • private



250
251
252
253
254
# File 'lib/mongo/crypt/binding.rb', line 250

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) ⇒ 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.

Set schema map on the Mongo::Crypt::Handle object

Parameters:

  • The schema map as a BSON::Document object

Raises:

  • If the schema map is not set successfully

API:

  • private



340
341
342
343
344
345
346
347
348
# File 'lib/mongo/crypt/binding.rb', line 340

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

.validate_document(data) ⇒ 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.

Note:

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

Parameters:

  • The data to be passed to libmongocrypt

Raises:

  • If the data is not a Hash

API:

  • private



1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
# File 'lib/mongo/crypt/binding.rb', line 1217

def self.validate_document(data)
  return if data.is_a?(Hash)

  if data.nil?
    message = "Attempted to pass nil data to libmongocrypt. " +
      "Data must be a Hash"
  else
    message = "Attempted to pass invalid data to libmongocrypt: #{data} " +
      "Data must be a Hash"
  end

  raise Error::CryptError.new(message)
end

Instance Method Details

#mongocrypt_crypto_fn(ctx, key, iv, input, output, status) ⇒ Bool

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.

Note:

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.

Parameters:

  • An optional pointer to a context object that may have been set when hooks were enabled.

  • A pointer to a mongocrypt_binary_t object that references the 32-byte AES encryption key.

  • A pointer to a mongocrypt_binary_t object that references the 16-byte AES IV.

  • A pointer to a mongocrypt_binary_t object that references the value to be encrypted/decrypted.

  • (out param) A pointer to a mongocrypt_binary_t object will have a reference to the encrypted/ decrypted value written to it by libmongocrypt.

  • A pointer to a mongocrypt_status_t object to which an error message will be written if encryption fails.

Returns:

  • Whether encryption/decryption was successful.

API:

  • private



1057
1058
1059
1060
1061
# File 'lib/mongo/crypt/binding.rb', line 1057

callback(
  :mongocrypt_crypto_fn,
  [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer],
  :bool
)

#mongocrypt_hash_fn(ctx, input, output, status) ⇒ Bool

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.

Note:

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.

Parameters:

  • An optional pointer to a context object that may have been set when hooks were enabled.

  • A pointer to a mongocrypt_binary_t object that references the value to be hashed.

  • (out param) A pointer to a mongocrypt_binary_t object will have a reference to the output value written to it by libmongocrypt.

  • A pointer to a mongocrypt_status_t object to which an error message will be written if encryption fails.

Returns:

  • Whether hashing was successful.

API:

  • private



1105
# File 'lib/mongo/crypt/binding.rb', line 1105

callback :mongocrypt_hash_fn, [:pointer, :pointer, :pointer, :pointer], :bool

#mongocrypt_hmac_fn(ctx, key, input, output, status) ⇒ Bool

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.

Note:

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.

Parameters:

  • An optional pointer to a context object that may have been set when hooks were enabled.

  • A pointer to a mongocrypt_binary_t object that references the 32-byte HMAC SHA encryption key.

  • A pointer to a mongocrypt_binary_t object that references the input value.

  • (out param) A pointer to a mongocrypt_binary_t object will have a reference to the output value written to it by libmongocrypt.

  • A pointer to a mongocrypt_status_t object to which an error message will be written if encryption fails.

Returns:

  • Whether HMAC-SHA was successful.

API:

  • private



1082
1083
1084
1085
1086
# File 'lib/mongo/crypt/binding.rb', line 1082

callback(
  :mongocrypt_hmac_fn,
  [:pointer, :pointer, :pointer, :pointer, :pointer],
  :bool
)

#mongocrypt_log_fn_t(level, message, len, ctx) ⇒ 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.

Note:

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

Parameters:

  • The log level; possible values defined by the log_level enum

  • The log message

  • The length of the message param, or -1 if the string is null terminated

  • An optional pointer to a context object when this callback was set

Returns:

  • Always nil.

API:

  • private



219
# File 'lib/mongo/crypt/binding.rb', line 219

callback :mongocrypt_log_fn_t, [:log_level, :string, :int, :pointer], :void

#mongocrypt_random_fn(ctx, output, count, status) ⇒ Bool

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.

Note:

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.

Parameters:

  • An optional pointer to a context object that may have been set when hooks were enabled.

  • (out param) A pointer to a mongocrypt_binary_t object will have a reference to the output value written to it by libmongocrypt.

  • The number of random bytes to return.

  • A pointer to a mongocrypt_status_t object to which an error message will be written if encryption fails.

Returns:

  • Whether hashing was successful.

API:

  • private



1123
# File 'lib/mongo/crypt/binding.rb', line 1123

callback :mongocrypt_random_fn, [:pointer, :pointer, :int, :pointer], :bool