pg; FddlZddlZddlmZmZmZddlmZddlm Z ej rddl m Z GddejZGd d eejZGd d eejZGd deejZejdeje jdZGddejeZeeje je jde je jfZGddeZ GddeZGddeeZGddeeZ dS)N)AlreadyFinalizedAlreadyUpdatedNotYetFinalized)CipherAlgorithm)modes)_CipherContextceZdZejdedefdZejdededefdZejdefdZ dS) CipherContextdatareturncdS)zk Processes the provided bytes through the cipher and returns the results as bytes. Nselfr s M/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyupdatezCipherContext.updatebufcdS)z Processes the provided bytes and writes the resulting data into the provided buffer. Returns the number of bytes written. Nrrr rs r update_intozCipherContext.update_into rrcdS)zM Returns the results of processing the final block as bytes. Nrrs rfinalizezCipherContext.finalize'rrN) __name__ __module__ __qualname__abcabstractmethodbytesrintrrrrrr r s 5 U       E c      %      rr ) metaclassc8eZdZejdeddfdZdS)AEADCipherContextr r NcdS)z3 Authenticates the provided bytes. Nrrs rauthenticate_additional_dataz.AEADCipherContext.authenticate_additional_data/rr)rrrrr r!r'rrrr%r%.sD  4      rr%c8eZdZejdedefdZdS)AEADDecryptionContexttagr cdS)z Returns the results of processing the final block as bytes and allows delayed passing of the authentication tag. Nr)rr*s rfinalize_with_tagz'AEADDecryptionContext.finalize_with_tag7rrN)rrrrr r!r,rrrr)r)6sD U u      rr)c4eZdZejdefdZdS)AEADEncryptionContextr cdS)zb Returns tag bytes. This is only available after encryption is finalized. Nrrs rr*zAEADEncryptionContext.tag@rrN)rrrrabstractpropertyr!r*rrrr.r.?s= U      rr.ModeT)bound covariantc eZdZ ddededejfdZejddde fd Z ejdd de fd Z d Z ejddde fd Z ejdd de fdZ dZ dddedeje e e ffdZdS)CipherN algorithmmodebackendct|tstd|1t|tjsJ||||_||_dS)Nz&Expected interface of CipherAlgorithm.) isinstancer TypeErrorrr1validate_for_algorithmr6r7)rr6r7r8s r__init__zCipher.__init__Nsl)_55 FDEE E  dEJ// / / /  ' ' 2 2 2" rrz'Cipher[modes.ModeWithAuthenticationTag]r cdSNrrs r encryptorzCipher.encryptora  r _CIPHER_TYPEcdSr?rrs rr@zCipher.encryptorgrArct|jtjr|jjt dddlm}||j |j}| |dS)Nz0Authentication tag must be None when encrypting.rr8Tencrypt) r:r7rModeWithAuthenticationTagr* ValueError,cryptography.hazmat.backends.openssl.backendr8create_symmetric_encryption_ctxr6 _wrap_ctxrr8ctxs rr@zCipher.encryptorms di!@ A A y}( F IHHHHH55 NDI  ~~c4~000rcdSr?rrs r decryptorzCipher.decryptorzrArcdSr?rrs rrPzCipher.decryptorrArc|ddlm}||j|j}||dS)NrrEFrF)rJr8create_symmetric_decryption_ctxr6r7rLrMs rrPzCipher.decryptorsJHHHHHH55 NDI  ~~c5~111rrN_BackendCipherContextrGct|jtjr |rt |St |St |Sr?)r:r7rrH_AEADEncryptionContext_AEADDecryptionContextr)rrNrGs rrLzCipher._wrap_ctxsM di!@ A A ' 3-c222-c222!#&& &rr?)rrrrr1typingAnyr=overloadr.r@r r)rPboolUnionrLrrrr5r5Mst # " & _ 7    _  _     _ 1 1 1 _ 7    _  _     _ 222 '* '59 ' 4mC  ' ' ' ' ' 'rr5cheZdZUejded<d dZdedefdZded ede fd Z defd Z dS) rrT_ctxrNr Nc||_dSr?)r^rrNs rr=z_CipherContext.__init__s  rr cb|jtd|j|SNContext was already finalized.)r^rrrs rrz_CipherContext.updates/ 9 "#CDD Dy%%%rrcd|jtd|j||Srb)r^rrrs rrz_CipherContext.update_intos1 9 "#CDD Dy$$T3///rcr|jtd|j}d|_|Srb)r^rrrs rrz_CipherContext.finalizes8 9 "#CDD Dy!!##  rrNrTr N) rrrrXOptional__annotations__r=r!rr"rrrrrrrs /1 2222&5&U&&&& 00E0c0000 %rrceZdZUejded<ejeed<ddZdeddfd Z d edefd Z d ed edefd Z defdZ d eddfdZ dS)_AEADCipherContextrTr^_tagrNr NcL||_d|_d|_d|_d|_dS)NrF)r^_bytes_processed_aad_bytes_processedrk_updatedr`s rr=z_AEADCipherContext.__init__s+ !$%!  r data_sizec|jtdd|_|xj|z c_|j|jjjkrAt d|jjj|jjjdS)NrcTz+{} has a maximum encrypted byte limit of {}) r^rrorm_mode_MAX_ENCRYPTED_BYTESrIformatname)rrps r _check_limitz_AEADCipherContext._check_limits 9 "#CDD D  *  49?#G G G=DDIO($)/*N  H Grr c|t||jJ|j|Sr?)rvlenr^rrs rrz_AEADCipherContext.updates@ #d))$$$y$$$y%%%rrc|t||jJ|j||Sr?)rvrxr^rrs rrz_AEADCipherContext.update_intosB #d))$$$y$$$y$$T3///rc|jtd|j}|jj|_d|_|Srb)r^rrr*rkrs rrz_AEADCipherContext.finalizesC 9 "#CDD Dy!!##IM   rc|jtd|jrtd|xjt |z c_|j|jjjkrAtd |jjj |jjj|j |dS)Nrcz'Update has been called on this context.z%{} has a maximum AAD byte limit of {}) r^rrorrnrxrr_MAX_AAD_BYTESrIrtrur'rs rr'z/_AEADCipherContext.authenticate_additional_datas 9 "#CDD D = L !JKK K !!SYY.!!  $ty'E E E7>>IO($)/*H  ..t44444rrf)rrrrXrgrhr!r=r"rvrrrr'rrrrjrjs /1 2222 /%     c d    &5&U&&&& 00E0c0000 %554555555rrjceZdZdedefdZdS)rWr*r c|jtd|j|}|jj|_d|_|Srb)r^rr,r*rk)rr*r s rr,z(_AEADDecryptionContext.finalize_with_tagsE 9 "#CDD Dy**3//IM   rN)rrrr!r,rrrrWrWs6UurrWc*eZdZedefdZdS)rVr cN|jtd|jJ|jS)Nz4You must finalize encryption before getting the tag.)r^rrkrs rr*z_AEADEncryptionContext.tags7 9 !I y$$$yrN)rrrpropertyr!r*rrrrVrVs9 UXrrV)!rrXcryptography.exceptionsrrr/cryptography.hazmat.primitives._cipheralgorithmr&cryptography.hazmat.primitives.ciphersr TYPE_CHECKING,cryptography.hazmat.backends.openssl.ciphersrrTABCMetar r%r)r.TypeVarrgr1Genericr5r\ ModeWithNonce ModeWithTweakECBModeWithInitializationVectorrBrjrWrVrrrrs   LKKKKK888888       ck    ,              -         -    v~ &/%*- L'L'L'L'L'V^D !L'L'L'^ L     *  , ]09595959595*959595x/1F/1Fr