lib/mongo/protocol/msg.rb
# Possibly encrypt this message with libmongocrypt. Message will only be
# encrypted if the specified client exists, that client has been given
# auto-encryption options, the client has not been instructed to bypass
# auto-encryption, and mongocryptd determines that this message is
# eligible for encryption. A message is eligible for encryption if it
# represents one of the command types allow-listed by libmongocrypt and it
# contains data that is required to be encrypted by a local or remote json schema.
#
# @param [ Mongo::Server::Connection ] connection The connection on which
#   the operation is performed.
# @param [ Mongo::Operation::Context ] context The operation context.
#
# @return [ Mongo::Protocol::Msg ] The encrypted message, or the original
#   message if encryption was not possible or necessary.
Possibly encrypt this message with libmongocrypt. Message will only be
encrypted if the specified client exists, that client has been given
auto-encryption options, the client has not been instructed to bypass
auto-encryption, and mongocryptd determines that this message is
eligible for encryption. A message is eligible for encryption if it
represents one of the command types allow-listed by libmongocrypt and it
contains data that is required to be encrypted by a local or remote json schema.
Possibly encrypt this message with libmongocrypt . Message will only be encrypted if the specified client exists that client has been given auto - encryption options the client has not been instructed to bypass auto - encryption and mongocryptd determines that this message is eligible for encryption . A message is eligible for encryption if it represents one of the command types allow - listed by libmongocrypt and it contains data that is required to be encrypted by a local or remote json schema .
def maybe_encrypt(connection, context)
        if context.encrypt?
          if connection.description.max_wire_version < 8
            raise Error::CryptError.new(
              "Cannot perform encryption against a MongoDB server older than " +
              "4.2 (wire version less than 8). Currently connected to server " +
              "with max wire version #{connection.description.max_wire_version}} " +
              "(Auto-encryption requires a minimum MongoDB version of 4.2)"
            )
          end
          db_name = @main_document[DATABASE_IDENTIFIER]
          cmd = merge_sections
          enc_cmd = context.encrypter.encrypt(db_name, cmd)
          if cmd.key?('$db') && !enc_cmd.key?('$db')
            enc_cmd['$db'] = cmd['$db']
          end
          Msg.new(@flags, @options, enc_cmd)
        else
          self
        end
      end
def maybe_encrypt ( connection , context ) if context . encrypt? if connection . description . max_wire_version < 8 raise Error :: CryptError . new ( "Cannot perform encryption against a MongoDB server older than " + "4.2 (wire version less than 8). Currently connected to server " + "with max wire version #{connection.description.max_wire_version}} " + "(Auto-encryption requires a minimum MongoDB version of 4.2)" ) end db_name = @main_document [ DATABASE_IDENTIFIER ] cmd = merge_sections enc_cmd = context . encrypter . encrypt ( db_name , cmd ) if cmd . key? ( '$db' ) && ! enc_cmd . key? ( '$db' ) enc_cmd [ '$db' ] = cmd [ '$db' ] end Msg . new ( @flags , @options , enc_cmd ) else self end end
Possibly encrypt this message with libmongocrypt.
Possibly encrypt this message with libmongocrypt .
# TODO verify compression happens later, i.e. when this method runs # the message is not compressed.
The encrypted message, or the original message if encryption was not possible or necessary.
The encrypted message or the original message if encryption was not possible or necessary .
 Mongo::Protocol::Msg 
connection
<not_specific>
context
<not_specific>
<not_specific>
context The operation context.
context The operation context .