MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / encrypt

Method encrypt

pymongo/synchronous/encryption.py:458–474  ·  view source on GitHub ↗

Encrypt a MongoDB command. :param database: The database for this command. :param cmd: A command document. :param codec_options: The CodecOptions to use while encoding `cmd`. :return: The encrypted command to execute.

(
        self, database: str, cmd: Mapping[str, Any], codec_options: CodecOptions[_DocumentTypeArg]
    )

Source from the content-addressed store, hash-verified

456 self._closed = False
457
458 def encrypt(
459 self, database: str, cmd: Mapping[str, Any], codec_options: CodecOptions[_DocumentTypeArg]
460 ) -> dict[str, Any]:
461 """Encrypt a MongoDB command.
462
463 :param database: The database for this command.
464 :param cmd: A command document.
465 :param codec_options: The CodecOptions to use while encoding `cmd`.
466
467 :return: The encrypted command to execute.
468 """
469 self._check_closed()
470 encoded_cmd = _dict_to_bson(cmd, False, codec_options)
471 with _wrap_encryption_errors():
472 encrypted_cmd = self._auto_encrypter.encrypt(database, encoded_cmd)
473 # TODO: PYTHON-1922 avoid decoding the encrypted_cmd.
474 return _inflate_bson(encrypted_cmd, DEFAULT_RAW_BSON_OPTIONS)
475
476 def decrypt(self, response: bytes | memoryview) -> Optional[bytes]:
477 """Decrypt a MongoDB command response.

Callers 15

test_encrypt_decryptMethod · 0.45
test_validationMethod · 0.45
test_bson_errorsMethod · 0.45
test_codec_optionsMethod · 0.45
test_closeMethod · 0.45
run_testMethod · 0.45
_test_corpusMethod · 0.45
_test_explicitMethod · 0.45
setUpMethod · 0.45

Calls 4

_check_closedMethod · 0.95
_dict_to_bsonFunction · 0.90
_inflate_bsonFunction · 0.90
_wrap_encryption_errorsFunction · 0.70

Tested by 15

test_encrypt_decryptMethod · 0.36
test_validationMethod · 0.36
test_bson_errorsMethod · 0.36
test_codec_optionsMethod · 0.36
test_closeMethod · 0.36
run_testMethod · 0.36
_test_corpusMethod · 0.36
_test_explicitMethod · 0.36
setUpMethod · 0.36