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

Method encrypt

pymongo/asynchronous/encryption.py:461–477  ·  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

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

Callers 3

commandFunction · 0.45
operation_to_commandMethod · 0.45
_encrypt_helperMethod · 0.45

Calls 4

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

Tested by

no test coverage detected