f'bUdZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z m Z mZmZmZmZmZmZmZmZ ddlmZddlmZddlmZdd lmZdd lmZd Z dd l#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0m1Z1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:ddl;mZ>ddl?m@Z@mAZAddlBmCZCmDZDmEZEmFZFmGZGmHZHddlImJZJddlKmLZLddlMmNZNddlOmPZPmQZQmRZRddlSmTZTddlUmVZVmWZWdd lXmYZYdd!lZm[Z[m\Z\dd"l]m^Z^dd#l_m`Z`e rdd$lmaZad%Zbe8Zcd&Zde,e eee fe('Zfd(egd)<e,e1*Zhejd8d+ZjGd,d-eZkGd.d/ZlGd0d1ZmGd2d3eeejZoGd4d5eeejZpGd6d7ee[Zqy#e!$rd Z e"ZYNwxYw)9z8Support for explicit client-side field level encryption.) annotationsN)deepcopy) TYPE_CHECKINGAnyDictGenericIteratorMappingMutableMappingOptionalSequenceUnioncast) AutoEncrypter)MongoCryptError)ExplicitEncrypter)MongoCryptOptions)MongoCryptCallbackTF) _dict_to_bsondecodeencode)STANDARD UUID_SUBTYPEBinary) CodecOptions) BSONError)DEFAULT_RAW_BSON_OPTIONSRawBSONDocument _inflate_bson)_csot) Collection)CONNECT_TIMEOUT)Cursor) _spawn_daemon)Database)AutoEncryptionOpts RangeOpts)ConfigurationErrorEncryptedCollectionErrorEncryptionErrorInvalidOperation PyMongoErrorServerSelectionTimeoutError) MongoClient)BLOCKING_IO_ERRORS) UpdateOne) PoolOptions_configured_socket_raise_connection_failure) ReadConcern)BulkWriteResult DeleteResult)get_ssl_context) _DocumentType_DocumentTypeArg) parse_host) WriteConcern)MongoCryptKmsContextii')document_classuuid_representationzCodecOptions[dict[str, Any]]_DATA_KEY_OPTS)r=c#bK dy#t$rt$r}t||d}~wwxYww)z2Context manager to wrap encryption related errors.N)r Exceptionr*)excs [/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/pymongo/encryption.py_wrap_encryption_errorsrD`s7,   ,c"+,s/ /, ',/cpeZdZ d dZd dZ d dZddZddZddZddZ ddZ dd Z y ) _EncryptionIOc ||tj||_nd|_ttt |j ttdtd|_ ||_ ||_ d|_ y)z8Internal class to perform I/O on behalf of pymongocrypt.Nmajority)level)w) codec_options read_concern write_concernF)weakrefref client_refrr!r with_options_KEY_VAULT_OPTSr4r;key_vault_collmongocryptd_clientopts_spawned)selfclientrSrTrUs rC__init__z_EncryptionIO.__init__nsx  %kk&1DO"DOEI  '  ' '-(z:*Z8 ( F #5  c |j}|j}|j}|jjj |}|t ddddddd}ttjtd}t|||}t|t\}} t|| f|} | j||j dkDr{| j#ttjtd| j%|j } | s t'd|j)| |j dkDr{| j1y#t*$rt-j.ddwxYw#| j1wxYw#t2t4f$rt6$r} t9|| f| Yd} ~ yd} ~ wwxYw)zuComplete a KMS request. :param kms_context: A :class:`MongoCryptKmsContext`. :return: None NFgMbP?)connect_timeoutsocket_timeout ssl_contextrzKMS connection closedz timed out)endpointmessage kms_providerrU_kms_ssl_contextsgetr7maxr clamp_remaining_KMS_CONNECT_TIMEOUTr1r: _HTTPS_PORTr2sendall bytes_needed settimeoutrecvOSErrorfeedr/sockettimeoutcloser,rrAr3) rW kms_contextr_r`providerctxr\rUhostportconndataerrors rC kms_requestz_EncryptionIO.kms_requests''%%++ii))--h7 ;"Ce334HI5Q+*   +6 d ;%tTlD9D  W%!..2OOC(=(=>R(SUV$WX99[%=%=>D%&=>>$$T* "..2 & <nn[1t; < o.   ; %tTlE : : ;s="F1BE F E==FFFG-GGc|j|jt|5}|D]}t|dtccdddS dddy#1swYyxYw)auGet the collection info for a namespace. The returned collection info is passed to libmongocrypt which reads the JSON schema. :param database: The database on which to run listCollections. :param filter: The filter to pass to listCollections. :return: The first document from the listCollections command response as BSON. )filterFN)rPlist_collectionsrrr?)rWdatabaser{cursordocs rCcollection_infoz_EncryptionIO.collection_infosc__ x ( 9 9QWAX 9 Y ]c$S%@@     sAAA#cd|_|jjxsdg}|j|jjt |y)z~Spawn mongocryptd. Note this method is thread safe; at most one mongocryptd will start successfully. T mongocryptdN)rVrU_mongocryptd_spawn_pathextend_mongocryptd_spawn_argsr$)rWargss rCspawnz_EncryptionIO.spawns@   11B]C DII556drZc|js&|jjs|jt |t }|j J |j |j|t }|jS#t$rY|jjr|j|j |j|t }Y|jSwxYw)zMark a command for encryption. :param database: The database on which to run this command. :param cmd: The BSON command to run. :return: The marked command response from mongocryptd. rK) rVrU_mongocryptd_bypass_spawnrrrrTcommandr-raw)rWr}cmd inflated_cmdress rC mark_commandz_EncryptionIO.mark_commands}}TYY%H%H JJL%S*BC &&222 ))(3;;,D<Cww+ yy22 JJL))(3;;,D<Cww s$BAC$#C$c#K|jJ|jjt|5}|D]}|j dddy#1swYyxYww)zYields one or more keys from the key vault. :param filter: The filter to pass to find. :return: A generator which yields the requested keys from the key vault. N)rSfindrr)rWr{r~keys rC fetch_keysz_EncryptionIO.fetch_keyss\""...  % %of&= > &gg    s3A!A A!AA!ct|t}|jd}t|tr|j t k7r td|jJ|jj||S)zInsert a data key into the key vault. :param data_key: The data key document to insert. :return: The _id of the inserted data key document. _idz/data_key _id must be Binary with a UUID subtype) rrRrc isinstancersubtyper TypeErrorrS insert_one)rWdata_keyraw_doc data_key_ids rCinsert_data_keyz_EncryptionIO.insert_data_keysm"(O<kk%( +v.+2E2E2UMN N""... &&w/rZct|S)zEncode a document to BSON. A document can be any mapping type (like :class:`dict`). :param doc: mapping type representing a document :return: The encoded BSON bytes. )r)rWrs rC bson_encodez_EncryptionIO.bson_encodesc{rZc|d|_d|_|jr"|jjd|_yy)zjRelease resources. Note it is not safe to call this method from __del__ or any GC hooks. N)rPrSrTrprWs rCrpz_EncryptionIO.closes; "  " "  # # ) ) +&*D # #rZN)rX'Optional[MongoClient[_DocumentTypeArg]]rSzCollection[_DocumentTypeArg]rTrrUr&)rqr<returnNone)r}zDatabase[Mapping[str, Any]]r{bytesrOptional[bytes]rr)r}strrrrr)r{rrzIterator[bytes])rrrr)rzMutableMapping[str, Any]rr) __name__ __module__ __qualname__rYryrrrrrrrprZrCrFrFmso75D  ! 42;h3=B $ 6   +rZrFc4eZdZdZdddZeddZd dZy) RewrapManyDataKeyResultzuResult object returned by a :meth:`~ClientEncryption.rewrap_many_data_key` operation. .. versionadded:: 4.2 Nc||_yN_bulk_write_result)rWbulk_write_results rCrYz RewrapManyDataKeyResult.__init__-s "3rZc|jS)aDThe result of the bulk write operation used to update the key vault collection with one or more rewrapped data keys. If :meth:`~ClientEncryption.rewrap_many_data_key` does not find any matching keys to rewrap, no bulk write operation will be executed and this field will be ``None``. rrs rCrz)RewrapManyDataKeyResult.bulk_write_result0s&&&rZcN|jjd|jdS)N()) __class__rrrs rC__repr__z RewrapManyDataKeyResult.__repr__:s'..))*!D,C,C+FaHHrZr)rOptional[BulkWriteResult]rr)rr)rr)rrr__doc__rYpropertyrrrrZrCrr's& 4''IrZrcHeZdZdZddZ d dZd dZd dZd dZy) _EncrypterzEncrypts and decrypts MongoDB commands. This class is used to support automatic encryption and decryption of MongoDB commands. c |jd}nt|jdt}|jd}nt|jdt}|j|_d|_ dd}|j |j }n |||}|jrd}n |||}|jjdd\}} ||| } t|jdt} t|| | |} t| t|j||j |j"|j||j$|_d|_y) zCreate a _Encrypter for a client. :param client: The encrypted MongoClient. :param opts: The encrypted client's :class:`AutoEncryptionOpts`. NFc|jjj|S|j |jS|j dd}||_|S)Nr) minPoolSizeauto_encryption_opts)options pool_options max_pool_size_internal_client _duplicate) encrypter mongo_clientinternal_clients rC_get_internal_clientz1_Encrypter.__init__.._get_internal_clientWs^##00>>F##))5 111*55!Z^5_O)8I &" "rZ.)connectserverSelectionTimeoutMS)crypt_shared_lib_pathcrypt_shared_lib_requiredbypass_encryptionencrypted_fields_mapbypass_query_analysis)rrrMongoClient[_DocumentTypeArg]rr) _schema_maprr?_encrypted_fields_map_bypass_auto_encryptionr_key_vault_client_key_vault_namespacesplitr._mongocryptd_uri_MONGOCRYPTD_TIMEOUT_MSrFrr_kms_providers_crypt_shared_lib_path_crypt_shared_lib_required_bypass_query_analysis_auto_encrypter_closed) rWrXrU schema_maprrkey_vault_clientmetadata_clientdbcollrSrT io_callbackss rCrYz_Encrypter.__init__Esu    #J&t'7'7OJ  % % -#' #01K1KUTb#c '+'C'C$ $ #! #1N # * #  ! ! -#55 3D&A   ' '"O24@O,,223:D)"-d3=H  ! !5Kb> % ^-?  -  ##&*&A&A*.*I*I"&">">%9&*&A&A   rZc|jt|d|}t5|jj ||}t |t cdddS#1swYyxYw)aEncrypt 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. FN) _check_closedrrDrencryptrr)rWr}rrK encoded_cmd encrypted_cmds rCrz_Encrypter.encrypts` #C > $ & J 0088;OM 0HI J J Js ,AA'c|jt5tt|jj |cdddS#1swYyxYw)zDecrypt a MongoDB command response. :param response: A MongoDB command response as BSON. :return: The decrypted command response. N)rrDrrrdecrypt)rWresponses rCrz_Encrypter.decryptsJ  $ & Gt33;;HEF G G Gs )AAc2|jr tdy)Nz"Cannot use MongoClient after close)rr+rs rCrz_Encrypter._check_closeds <<"#GH H rZcd|_|jj|jr"|jjd|_yy)zCleanup resources.TN)rrrprrs rCrpz_Encrypter.closesC  ""$   ! ! ' ' )$(D ! !rZN)rXrrUr&)r}rrMapping[str, Any]rKCodecOptions[_DocumentTypeArg]rzdict[str, Any])rrrrr) rrrrrYrrrrprrZrCrr>sH ?BJJ"3JDbJ J$ GI)rZrc,eZdZdZdZ dZ dZ dZ dZy) Algorithmz9An enum that defines the supported encryption algorithms.z+AEAD_AES_256_CBC_HMAC_SHA_512-Deterministicz$AEAD_AES_256_CBC_HMAC_SHA_512-RandomIndexed Unindexed RangePreviewN) rrrr+AEAD_AES_256_CBC_HMAC_SHA_512_Deterministic$AEAD_AES_256_CBC_HMAC_SHA_512_RandomINDEXED UNINDEXED RANGEPREVIEWrrZrCrrs9C2_/6+Q(/GI"LrZrceZdZdZdZ dZy) QueryTypezmAn enum that defines the supported values for explicit encryption query_type. .. versionadded:: 4.2 equality rangePreviewN)rrrrEQUALITYrrrZrCrrs H8!LrZrceZdZdZ d ddZ d ddZ d ddZ d ddZ d ddZ d ddZ d d Z d!d Z d"d Z d#d Z d$d Zd%dZd&dZ d d'dZd(dZd)dZd*dZd*dZy)+ClientEncryptionz,Explicit client-side field level encryption.Ncts tdt|ts t d||_||_||_||_|jdd\}}|||}t|||} td|d| |_ t|jt|d|_|jj J|jj |_y)aExplicit client-side field level encryption. The ClientEncryption class encapsulates explicit operations on a key vault collection that cannot be done directly on a MongoClient. Similar to configuring auto encryption on a MongoClient, it is constructed with a MongoClient (to a MongoDB cluster containing the key vault collection), KMS provider configuration, and keyVaultNamespace. It provides an API for explicitly encrypting and decrypting values, and creating data keys. It does not provide an API to query keys from the key vault collection, as this can be done directly on the MongoClient. See :ref:`explicit-client-side-encryption` for an example. :param kms_providers: Map of KMS provider options. The `kms_providers` map values differ by provider: - `aws`: Map with "accessKeyId" and "secretAccessKey" as strings. These are the AWS access key ID and AWS secret access key used to generate KMS messages. An optional "sessionToken" may be included to support temporary AWS credentials. - `azure`: Map with "tenantId", "clientId", and "clientSecret" as strings. Additionally, "identityPlatformEndpoint" may also be specified as a string (defaults to 'login.microsoftonline.com'). These are the Azure Active Directory credentials used to generate Azure Key Vault messages. - `gcp`: Map with "email" as a string and "privateKey" as `bytes` or a base64 encoded string. Additionally, "endpoint" may also be specified as a string (defaults to 'oauth2.googleapis.com'). These are the credentials used to generate Google Cloud KMS messages. - `kmip`: Map with "endpoint" as a host with required port. For example: ``{"endpoint": "example.com:443"}``. - `local`: Map with "key" as `bytes` (96 bytes in length) or a base64 encoded string which decodes to 96 bytes. "key" is the master key used to encrypt/decrypt data keys. This key should be generated and stored as securely as possible. KMS providers may be specified with an optional name suffix separated by a colon, for example "kmip:name" or "aws:name". Named KMS providers do not support :ref:`CSFLE on-demand credentials`. :param key_vault_namespace: The namespace for the key vault collection. The key vault collection contains all data keys used for encryption and decryption. Data keys are stored as documents in this MongoDB collection. Data keys are protected with encryption by a KMS provider. :param key_vault_client: A MongoClient connected to a MongoDB cluster containing the `key_vault_namespace` collection. :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions` to use when encoding a value for encryption and decoding the decrypted BSON value. This should be the same CodecOptions instance configured on the MongoClient, Database, or Collection used to access application data. :param kms_tls_options: A map of KMS provider names to TLS options to use when creating secure connections to KMS providers. Accepts the same TLS options as :class:`pymongo.mongo_client.MongoClient`. For example, to override the system default CA file:: kms_tls_options={'kmip': {'tlsCAFile': certifi.where()}} Or to supply a client certificate:: kms_tls_options={'kmip': {'tlsCertificateKeyFile': 'client.pem'}} .. versionchanged:: 4.0 Added the `kms_tls_options` parameter and the "kmip" KMS provider. .. versionadded:: 3.9 zclient-side field level encryption requires the pymongocrypt library: install a compatible version with: python -m pip install 'pymongo[encryption]'zDcodec_options must be an instance of bson.codec_options.CodecOptionsrr)kms_tls_optionsN)_HAVE_PYMONGOCRYPTr(rrrrrr_codec_optionsrr&rF _io_callbacksrr _encryptionrS_key_vault_coll) rW kms_providerskey_vault_namespacerrKr rrrSrUs rCrYzClientEncryption.__init__s^"$>  -6bc c+$7!!1+&,,S!4D)"-d3! . 7D .$7 -    1- F !!00<<<#11@@rZc ~t|}t|dD]E\}}t|ts|j d) |j |||d|d<G||d<d|d< |jd d|i||fS#t $r} t| || d} ~ wwxYw#t$r} t| || d} ~ wwxYw) au Create a collection with encryptedFields. .. warning:: This function does not update the encryptedFieldsMap in the client's AutoEncryptionOpts, thus the user must create a new client after calling this function with the encryptedFields returned. Normally collection creation is automatic. This method should only be used to specify options on creation. :class:`~pymongo.errors.EncryptionError` will be raised if the collection already exists. :param name: the name of the collection to create :param encrypted_fields: Document that describes the encrypted fields for Queryable Encryption. The "keyId" may be set to ``None`` to auto-generate the data keys. For example: .. code-block: python { "escCollection": "enxcol_.encryptedCollection.esc", "ecocCollection": "enxcol_.encryptedCollection.ecoc", "fields": [ { "path": "firstName", "keyId": Binary.from_uuid(UUID('00000000-0000-0000-0000-000000000000')), "bsonType": "string", "queries": {"queryType": "equality"} }, { "path": "ssn", "keyId": Binary.from_uuid(UUID('04104104-1041-0410-4104-104104104104')), "bsonType": "string" } ] } :param kms_provider: the KMS provider to be used :param master_key: Identifies a KMS-specific key used to encrypt the new data key. If the kmsProvider is "local" the `master_key` is not applicable and may be omitted. :param kwargs: additional keyword arguments are the same as "create_collection". All optional `create collection command`_ parameters should be passed as keyword arguments to this method. See the documentation for :meth:`~pymongo.database.Database.create_collection` for all valid options. :raises: - :class:`~pymongo.errors.EncryptedCollectionError`: When either data-key creation or creating the collection fails. .. versionadded:: 4.4 .. _create collection command: https://mongodb.com/docs/manual/reference/command/create fieldskeyIdN)ra master_keyencryptedFieldsF check_existsnamer) r enumeraterdictrccreate_data_keyr*r)create_collectionrA) rWr}rencrypted_fieldsrarkwargsifieldrBs rCcreate_encrypted_collectionz,ClientEncryption.create_encrypted_collectionMs~$$45!"28"<=HAu%&599W+=+ES=A=Q=Q%1#->R>$X.q1':>%5 !!&~ K***???   'S238HIsRS K*30@As J Ks0B-B! B BB! B<* B77B<c |jt5tt|jj ||||cdddS#1swYyxYw)a Create and insert a new data key into the key vault collection. :param kms_provider: The KMS provider to use. Supported values are "aws", "azure", "gcp", "kmip", "local", or a named provider like "kmip:name". :param master_key: Identifies a KMS-specific key used to encrypt the new data key. If the kmsProvider is "local" the `master_key` is not applicable and may be omitted. If the `kms_provider` type is "aws" it is required and has the following fields:: - `region` (string): Required. The AWS region, e.g. "us-east-1". - `key` (string): Required. The Amazon Resource Name (ARN) to the AWS customer. - `endpoint` (string): Optional. An alternate host to send KMS requests to. May include port number, e.g. "kms.us-east-1.amazonaws.com:443". If the `kms_provider` type is "azure" it is required and has the following fields:: - `keyVaultEndpoint` (string): Required. Host with optional port, e.g. "example.vault.azure.net". - `keyName` (string): Required. Key name in the key vault. - `keyVersion` (string): Optional. Version of the key to use. If the `kms_provider` type is "gcp" it is required and has the following fields:: - `projectId` (string): Required. The Google cloud project ID. - `location` (string): Required. The GCP location, e.g. "us-east1". - `keyRing` (string): Required. Name of the key ring that contains the key to use. - `keyName` (string): Required. Name of the key to use. - `keyVersion` (string): Optional. Version of the key to use. - `endpoint` (string): Optional. Host with optional port. Defaults to "cloudkms.googleapis.com". If the `kms_provider` type is "kmip" it is optional and has the following fields:: - `keyId` (string): Optional. `keyId` is the KMIP Unique Identifier to a 96 byte KMIP Secret Data managed object. If keyId is omitted, the driver creates a random 96 byte KMIP Secret Data managed object. - `endpoint` (string): Optional. Host with optional port, e.g. "example.vault.azure.net:". :param key_alt_names: An optional list of string alternate names used to reference a key. If a key is created with alternate names, then encryption may refer to the key by the unique alternate name instead of by ``key_id``. The following example shows creating and referring to a data key by alternate name:: client_encryption.create_data_key("local", key_alt_names=["name1"]) # reference the key with the alternate name client_encryption.encrypt("457-55-5462", key_alt_name="name1", algorithm=Algorithm.AEAD_AES_256_CBC_HMAC_SHA_512_Random) :param key_material: Sets the custom key material to be used by the data key for encryption and decryption. :return: The ``_id`` of the created data key document as a :class:`~bson.binary.Binary` with subtype :data:`~bson.binary.UUID_SUBTYPE`. .. versionchanged:: 4.2 Added the `key_material` parameter. )r key_alt_names key_materialN)rrDrrr r)rWrarr"r#s rCrz ClientEncryption.create_data_keys\X  $ &   00 )"/!- 1   s -AAc |jt|tjrt j |}|.t|tr|j tk(s tdtd|i|j} d} |r!t|j|j} t5|jj| |||||| |} t| dcdddS#1swYyxYw)Nz2key_id must be a bson.binary.Binary with subtype 4vrvalue algorithmkey_id key_alt_name query_typecontention_factor range_opts is_expression)rruuidUUIDr from_uuidrrrrr documentrDr rr) rWr'r(r)r*r+r,r-r.rrange_opts_bytes encrypted_docs rC_encrypt_helperz ClientEncryption._encrypt_helpers  fdii (%%f-F   vv &6>>\+IPQ Q %L--   %##"11  % & . ,,44#)%"3++5 M-(- . . .s 81C33C<c Ptt|j|||||||dS)aEncrypt a BSON value with a given key and algorithm. Note that exactly one of ``key_id`` or ``key_alt_name`` must be provided. :param value: The BSON value to encrypt. :param algorithm` (string): The encryption algorithm to use. See :class:`Algorithm` for some valid options. :param key_id: Identifies a data key by ``_id`` which must be a :class:`~bson.binary.Binary` with subtype 4 ( :attr:`~bson.binary.UUID_SUBTYPE`). :param key_alt_name: Identifies a key vault document by 'keyAltName'. :param query_type` (str): The query type to execute. See :class:`QueryType` for valid options. :param contention_factor` (int): The contention factor to use when the algorithm is :attr:`Algorithm.INDEXED`. An integer value *must* be given when the :attr:`Algorithm.INDEXED` algorithm is used. :param range_opts: Experimental only, not intended for public use. :return: The encrypted value, a :class:`~bson.binary.Binary` with subtype 6. .. versionchanged:: 4.7 ``key_id`` can now be passed in as a :class:`uuid.UUID`. .. versionchanged:: 4.2 Added the `query_type` and `contention_factor` parameters. Fr&)rrr5)rWr'r(r)r*r+r,r-s rCrzClientEncryption.encrypt"s@J   #)%"3%# !   rZc Ptt|j|||||||dS)aEncrypt a BSON expression with a given key and algorithm. Note that exactly one of ``key_id`` or ``key_alt_name`` must be provided. :param expression: The BSON aggregate or match expression to encrypt. :param algorithm` (string): The encryption algorithm to use. See :class:`Algorithm` for some valid options. :param key_id: Identifies a data key by ``_id`` which must be a :class:`~bson.binary.Binary` with subtype 4 ( :attr:`~bson.binary.UUID_SUBTYPE`). :param key_alt_name: Identifies a key vault document by 'keyAltName'. :param query_type` (str): The query type to execute. See :class:`QueryType` for valid options. :param contention_factor` (int): The contention factor to use when the algorithm is :attr:`Algorithm.INDEXED`. An integer value *must* be given when the :attr:`Algorithm.INDEXED` algorithm is used. :param range_opts: Experimental only, not intended for public use. :return: The encrypted expression, a :class:`~bson.RawBSONDocument`. .. versionchanged:: 4.7 ``key_id`` can now be passed in as a :class:`uuid.UUID`. .. versionadded:: 4.4 Tr&)rrr5)rW expressionr(r)r*r+r,r-s rCencrypt_expressionz#ClientEncryption.encrypt_expressionUs@J    #)%"3%" !   rZc:|jt|tr|jdk(s t dt 5t d|i}|jj|}t||jdcdddS#1swYyxYw)zDecrypt an encrypted value. :param value` (Binary): The encrypted value, a :class:`~bson.binary.Binary` with subtype 6. :return: The decrypted BSON value. z)rWr*s rCget_key_by_alt_namez$ClientEncryption.get_key_by_alt_names> ##///##,,m\-JKKrZc |jddddd|ggiddddd |gid igiiig}|jJ|jjd |i|S) aRemove ``key_alt_name`` from the set of keyAltNames in the key document with UUID ``id``. Also removes the ``keyAltNames`` field from the key document if it would otherwise be empty. :param `id`: The UUID of a key a which must be a :class:`~bson.binary.Binary` with subtype 4 ( :attr:`~bson.binary.UUID_SUBTYPE`). :param `key_alt_name`: The key alternate name to remove. :return: Returns the previous version of the key document. .. versionadded:: 4.2 $setrIz$condz$eqz $keyAltNamesz$$REMOVEz$filterz$nez$$this)inputcondrrJ)rWrAr*pipelines rCremove_key_alt_namez$ClientEncryption.remove_key_alt_names !"^l^$DE& )-;-2X|4L,M," " $   $##///##77 XNNrZc| | td|jt5|jj |||}|t cdddS dddt t}g}|dD]4}|d|ddddid }td |d i|} |j| 6|s t S|jJ|jj|} t | S#1swYxYw) aDecrypts and encrypts all matching data keys in the key vault with a possibly new `master_key` value. :param filter: A document used to filter the data keys. :param provider: The new KMS provider to use to encrypt the data keys, or ``None`` to use the current KMS provider(s). :param `master_key`: The master key fields corresponding to the new KMS provider when ``provider`` is not ``None``. :return: A :class:`RewrapManyDataKeyResult`. This method allows you to re-encrypt all of your data-keys with a new CMK, or master key. Note that this does *not* require re-encrypting any of the data in your encrypted collections, but rather refreshes the key that protects the keys that encrypt the data: .. code-block:: python client_encryption.rewrap_many_data_key( filter={"keyAltNames": "optional filter for which keys you want to update"}, master_key={ "provider": "azure", # replace with your cloud provider "master_key": { # put the rest of your master_key options here "key": "" }, }, ) .. versionadded:: 4.2 Nz1A provider must be given if a master_key is givenr% keyMaterial masterKey)rWrX updateDateT)rQz $currentDater) r(rrDr rewrap_many_data_keyrrrr0appendr bulk_write) rWr{rrr raw_resultr replacementsr update_modelopresults rCrZz%ClientEncryption.rewrap_many_data_keys F  !h&6$%XY Y  $ & 1))>>vxQ[\J!.0 1 1! 1 "*.FG 3&v..% 1 1s )C44C=c|Srrrs rC __enter__zClientEncryption.__enter__?s rZc$|jyr)rp)rWexc_typeexc_valexc_tbs rC__exit__zClientEncryption.__exit__Bs  rZc2|j tdy)Nz"Cannot use closed ClientEncryption)r r+rs rCrzClientEncryption._check_closedEs    #"#GH H $rZc|jrC|jj|jjd|_d|_yy)aERelease resources. Note that using this class in a with-statement will automatically call :meth:`close`:: with ClientEncryption(...) as client_encryption: encrypted = client_encryption.encrypt(value, ...) decrypted = client_encryption.decrypt(encrypted) N)r rpr rs rCrpzClientEncryption.closeIsF       $ $ &    " " $!%D #D  rZr) rrrrrrrKrr Optional[Mapping[str, Any]]rr)NN)r}zDatabase[_DocumentTypeArg]rrrrra Optional[str]rrkrrrz6tuple[Collection[_DocumentTypeArg], Mapping[str, Any]])NNN) rarrrkr"zOptional[Sequence[str]]r#rrr)NNNNNF)r'rr(rr)"Optional[Union[Binary, uuid.UUID]]r*rlr+rlr, Optional[int]r-Optional[RangeOpts]r.boolrr)NNNNN)r'rr(rr)rmr*rlr+rlr,rnr-rorr)r8rr(rr)rmr*rlr+rlr,rnr-rorr)r'rrr)rArrOptional[RawBSONDocument])rzCursor[RawBSONDocument])rArrr6)rArr*rrr)r*rrrq)rArr*rrrq)r{rrrrlrrkrr)rzClientEncryption[_DocumentType])rerrfrrgrrrr)rrrrrYr rr5rr9rrBrDrGrMrOrUrZrcrhrrprrZrCrrs68< lA(lA!lA8 lA 6 lA 5 lA lAf'+26 QK,QKQK, QK $ QK 0 QKQK @QKl3715(, VV0V/ V & V  Vx6:&*$(+/*.#(.(.(.3 (. $ (. " (.)(.((.(. (.\6:&*$(+/*.1 1 1 3 1 $ 1 " 1 )1 (1  1 n6:&*$(+/*.1 %1 1 3 1 $ 1 " 1 )1 (1  1 fQ" : - <M" L"ON#'26 8/!8/ 8/0 8/ ! 8/tI$rZr)rzIterator[None])rr __future__r contextlibenumrnr/rNcopyrtypingrrrrr r r r r rrpymongocrypt.auto_encrypterrpymongocrypt.errorsrpymongocrypt.explicit_encrypterrpymongocrypt.mongocryptrpymongocrypt.state_machinerr  ImportErrorobjectbsonrrr bson.binaryrrrbson.codec_optionsr bson.errorsr bson.raw_bsonrrrpymongor pymongo.collectionr!pymongo.commonr"pymongo.cursorr#pymongo.daemonr$pymongo.databaser%pymongo.encryption_optionsr&r'pymongo.errorsr(r)r*r+r,r-pymongo.mongo_clientr.pymongo.networkr/pymongo.operationsr0 pymongo.poolr1r2r3pymongo.read_concernr4pymongo.resultsr5r6pymongo.ssl_supportr7pymongo.typingsr8r9pymongo.uri_parserr:pymongo.write_concernr;r<rgrfrrr?__annotations__rRcontextmanagerrDrFrrEnumrrrrrZrCrs?"       93A9= /.66+!RR)*!(%D-.(SS,9/;).< &/;S>x0, o>  , ,w+&w+tII.o)o)dTYY6TYY"| $w}-| $]   s F!! F.-F.