123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Crypt::DataKeyContext Private

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Context, Forwardable
Instance Chain:
self, Context
Inherits: Mongo::Crypt::Context
Defined in: lib/mongo/crypt/data_key_context.rb

Overview

A Context object initialized specifically for the purpose of creating a data key in the key management system.

Class Method Summary

Context - Inherited

.new

Create a new Context object.

Instance Attribute Summary

Context - Inherited

Instance Method Summary

Context - Inherited

#bson_mode

Which BSON mode to use when creating documents from the outcome of the state machine.

#run_state_machine

Runs the mongocrypt_ctx_t state machine and handles all I/O on behalf of.

#state

Returns the state of the mongocrypt_ctx_t.

#azure_access_token

Returns an Azure access token, retrieving it if necessary.

#feed_collection_info, #feed_kms,
#gcp_access_token

Retrieves a GCP access token.

#mongocrypt_done

Indicate that state machine is done feeding I/O responses back to libmongocrypt.

#mongocrypt_feed

Feeds the result of a ::Mongo operation back to libmongocrypt.

#provide_collection_info, #provide_collection_info_with_db, #provide_keys, #provide_markings,
#retrieve_kms_credentials

Retrieves KMS credentials for providers that are configured for automatic credentials retrieval.

Constructor Details

.new(mongocrypt, io, master_key_document, key_alt_names, key_material) ⇒ DataKeyContext

Create a new DataKeyContext object

Parameters:

  • mongocrypt (Mongo::Crypt::Handle)

    a Handle that wraps a mongocrypt_t object used to create a new mongocrypt_ctx_t

  • io (Mongo::Crypt::EncryptionIO)

    An object that performs all driver I/O on behalf of libmongocrypt

  • master_key_document (Mongo::Crypt::KMS::MasterKeyDocument)

    The master key document that contains master encryption key parameters.

  • key_alt_names (Array<String> | nil)

    An optional array of strings specifying alternate names for the new data key.

  • :key_material (String | nil)

    Optional 96 bytes to use as custom key material for the data key being created. If :key_material option is given, the custom key material is used for encrypting and decrypting data.

[ GitHub ]

  
# File 'lib/mongo/crypt/data_key_context.rb', line 38

def initialize(mongocrypt, io, master_key_document, key_alt_names, key_material)
  super(mongocrypt, io)
  Binding.ctx_setopt_key_encryption_key(self, master_key_document.to_document)
  set_key_alt_names(key_alt_names) if key_alt_names
  Binding.ctx_setopt_key_material(self, BSON::Binary.new(key_material)) if key_material
  initialize_ctx
end

Instance Method Details

#initialize_ctx (private)

Initializes the underlying mongocrypt_ctx_t object

[ GitHub ]

  
# File 'lib/mongo/crypt/data_key_context.rb', line 63

def initialize_ctx
  Binding.ctx_datakey_init(self)
end

#set_key_alt_names(key_alt_names) (private)

Set the alt names option on the context

Raises:

  • (ArgumentError.new)
[ GitHub ]

  
# File 'lib/mongo/crypt/data_key_context.rb', line 49

def set_key_alt_names(key_alt_names)
  raise ArgumentError.new, 'The :key_alt_names option must be an Array' unless key_alt_names.is_a?(Array)

  unless key_alt_names.all? { |key_alt_name| key_alt_name.is_a?(String) }
    raise ArgumentError.new(
      "#{key_alt_names} contains an invalid alternate key name. All " +
      'values of the :key_alt_names option Array must be Strings'
    )
  end

  Binding.ctx_setopt_key_alt_names(self, key_alt_names)
end