3Tf^ ddlmZddlZddlZddlmZmZmZddlm Z ddl m Z ejrddl mZGddej ZGd d eej ZGd d eej ZGddeej Zej*dej,e j.dZGddej0eZeej4e j6e j8de j:e j<fZGddeZGddeZ Gdde eZ!Gdde eZ"y)) annotationsN)AlreadyFinalizedAlreadyUpdatedNotYetFinalized)CipherAlgorithm)modes)_CipherContextc~eZdZejddZejddZejddZy) CipherContextcy)zk Processes the provided bytes through the cipher and returns the results as bytes. Nselfdatas M/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyupdatezCipherContext.updatecy)z Processes the provided bytes and writes the resulting data into the provided buffer. Returns the number of bytes written. Nr rrbufs r update_intozCipherContext.update_into rrcy)zM Returns the results of processing the final block as bytes. Nr rs rfinalizezCipherContext.finalize'rrNrbytesreturnrrrrrrintrr)__name__ __module__ __qualname__abcabstractmethodrrrr rrr r sN        rr ) metaclassc2eZdZejddZy)AEADCipherContextcy)z3 Authenticates the provided bytes. Nr rs rauthenticate_additional_dataz.AEADCipherContext.authenticate_additional_data/rrNrrrNone)r"r#r$r%r&r+r rrr)r).s  rr)c2eZdZejddZy)AEADDecryptionContextcy)z Returns the results of processing the final block as bytes and allows delayed passing of the authentication tag. Nr )rtags rfinalize_with_tagz'AEADDecryptionContext.finalize_with_tag7rrNr1rrr)r"r#r$r%r&r2r rrr/r/6s  rr/c<eZdZeej ddZy)AEADEncryptionContextcy)zb Returns tag bytes. This is only available after encryption is finalized. Nr rs rr1zAEADEncryptionContext.tag@rrNr!)r"r#r$propertyr%r&r1r rrr5r5?s"   rr5ModeT)bound covariantceZdZ d d dZej d dZej d dZdZej ddZej d dZdZ dd Zy)CipherNct|ts td|-t|tjsJ|j |||_||_y)Nz&Expected interface of CipherAlgorithm.) isinstancer TypeErrorrr8validate_for_algorithm algorithmmode)rrArBbackends r__init__zCipher.__init__OsR )_5DE E  dEJJ/ //  ' ' 2" rcyNr rs r encryptorzCipher.encryptora rcyrFr rs rrGzCipher.encryptorgrHrc t|jtjr!|jj t dddlm}|j|j|j}|j|dS)Nz0Authentication tag must be None when encrypting.rrCTencrypt) r>rBrModeWithAuthenticationTagr1 ValueError,cryptography.hazmat.backends.openssl.backendrCcreate_symmetric_encryption_ctxrA _wrap_ctxrrCctxs rrGzCipher.encryptormsl dii!@!@ Ayy}}( F I55 NNDII ~~c4~00rcyrFr rs r decryptorzCipher.decryptorzrHrcyrFr rs rrVzCipher.decryptorrHrcddlm}|j|j|j}|j |dS)NrrKFrL)rPrCcreate_symmetric_decryption_ctxrArBrRrSs rrVzCipher.decryptors7H55 NNDII ~~c5~11rct|jtjr|r t |St |St |SrF)r>rBrrN_AEADEncryptionContext_AEADDecryptionContextr )rrTrMs rrRzCipher._wrap_ctxs< dii!@!@ A-c22-c22!#& &rrF)rArrBr8rCz typing.Anyrr-)r'Cipher[modes.ModeWithAuthenticationTag]rr5)r _CIPHER_TYPErr )rr]rr/)rT_BackendCipherContextrMboolrzItyping.Union[AEADEncryptionContext, AEADDecryptionContext, CipherContext]) r"r#r$rDtypingoverloadrGrVrRr rrr<r<Ns # "   $ __ 5    __    1 __ 5    __    2 '( '37 '  'rr<c8eZdZUded<ddZd dZd dZd dZy) r &typing.Optional[_BackendCipherContext]_ctxc||_yrF)rerrTs rrDz_CipherContext.__init__s  rcf|j td|jj|SNContext was already finalized.)rerrrs rrz_CipherContext.updates- 99 "#CD Dyy%%rch|j td|jj||Sri)rerrrs rrz_CipherContext.update_intos/ 99 "#CD Dyy$$T3//rcv|j td|jj}d|_|Sri)rerrrs rrz_CipherContext.finalizes6 99 "#CD Dyy!!#  rNrTr_rr-rrr!)r"r#r$__annotations__rDrrrr rrr r s 00& 0 rr cReZdZUded<ded<d dZd dZddZddZdd Zdd Z y )_AEADCipherContextrdreztyping.Optional[bytes]_tagcJ||_d|_d|_d|_d|_y)NrF)re_bytes_processed_aad_bytes_processedrq_updatedrgs rrDz_AEADCipherContext.__init__s' !$%!  rcr|j tdd|_|xj|z c_|j|jjj kDrWt dj|jjj|jjj y)NrjTz+{} has a maximum encrypted byte limit of {}) rerrurs_mode_MAX_ENCRYPTED_BYTESrOformatname)r data_sizes r _check_limitz_AEADCipherContext._check_limits 99 "#CD D  *  499??#G#G G=DDIIOO(($))//*N*N  Hrc|jt||jJ|jj|SrF)r|lenrerrs rrz_AEADCipherContext.updates9 #d)$yy$$$yy%%rc|jt||jJ|jj||SrF)r|r~rerrs rrz_AEADCipherContext.update_intos; #d)$yy$$$yy$$T3//rc|j td|jj}|jj|_d|_|Sri)rerrr1rqrs rrz_AEADCipherContext.finalizesE 99 "#CD Dyy!!#IIMM   rc|j td|jr td|xjt |z c_|j|jj jkDrWtdj|jj j|jj j|jj|y)Nrjz'Update has been called on this context.z%{} has a maximum AAD byte limit of {}) rerrurrtr~rw_MAX_AAD_BYTESrOryrzr+rs rr+z/_AEADCipherContext.authenticate_additional_datas 99 "#CD D == !JK K !!SY.!  $ $tyy'E'E E7>>IIOO(($))//*H*H  ..t4rNrm)r{r rr-rrr!r,) r"r#r$rnrDr|rrrr+r rrrprps, 00   & 0 5rrpceZdZddZy)r\c|j td|jj|}|jj|_d|_|Sri)rerr2r1rq)rr1rs rr2z(_AEADDecryptionContext.finalize_with_tagsG 99 "#CD Dyy**3/IIMM   rNr3)r"r#r$r2r rrr\r\srr\ceZdZeddZy)r[cd|j td|jJ|jS)Nz4You must finalize encryption before getting the tag.)rerrqrs rr1z_AEADEncryptionContext.tags8 99 !I yy$$$yyrNr!)r"r#r$r7r1r rrr[r[s rr[)# __future__rr%racryptography.exceptionsrrr/cryptography.hazmat.primitives._cipheralgorithmr&cryptography.hazmat.primitives.ciphersr TYPE_CHECKING,cryptography.hazmat.backends.openssl.ciphersr r_ABCMetar r)r/r5TypeVarOptionalr8Genericr<Union ModeWithNonce ModeWithTweakECBModeWithInitializationVectorr^rpr\r[r rrrs3 #  L8   ckk ,   -  - v~~ &//%**- K'V^^D !K'\ LL     **  , ]095*95x/1F/1Fr