B \Úæ`ìã@s‚ddlmZmZmZddlZddlZddlmZddlm Z m Z m Z m Z m Z ddlmZddlmZe ej¡Gdd„deƒƒZe ej¡Gd d „d eƒƒZe ej¡Gd d „d eƒƒZe ej¡Gd d„deƒƒZe ej¡Gdd„deƒƒZe ej¡Gdd„deƒƒZGdd„deƒZe e¡Gdd„deƒƒZe e¡e e¡e e¡Gdd„deƒƒƒƒZe e¡Gdd„deƒƒZdS)é)Úabsolute_importÚdivisionÚprint_functionN)Úutils)ÚAlreadyFinalizedÚAlreadyUpdatedÚNotYetFinalizedÚUnsupportedAlgorithmÚ_Reasons)Ú CipherBackend)Úmodesc@s(eZdZejdd„ƒZejdd„ƒZdS)ÚCipherAlgorithmcCsdS)zE A string naming this mode (e.g. "AES", "Camellia"). N©)Úselfrrú^/opt/alt/python37/lib64/python3.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyÚnameszCipherAlgorithm.namecCsdS)zW The size of the key being used as an integer in bits (e.g. 128, 256). Nr)rrrrÚkey_sizeszCipherAlgorithm.key_sizeN)Ú__name__Ú __module__Ú __qualname__ÚabcÚabstractpropertyrrrrrrr sr c@seZdZejdd„ƒZdS)ÚBlockCipherAlgorithmcCsdS)zK The size of a block as an integer in bits (e.g. 64, 128). Nr)rrrrÚ block_size%szBlockCipherAlgorithm.block_sizeN)rrrrrrrrrrr#src@s6eZdZejdd„ƒZejdd„ƒZejdd„ƒZdS)Ú CipherContextcCsdS)zk Processes the provided bytes through the cipher and returns the results as bytes. Nr)rÚdatarrrÚupdate.szCipherContext.updatecCsdS)z“ Processes the provided bytes and writes the resulting data into the provided buffer. Returns the number of bytes written. Nr)rrÚbufrrrÚ update_into5szCipherContext.update_intocCsdS)zM Returns the results of processing the final block as bytes. Nr)rrrrÚfinalize<szCipherContext.finalizeN)rrrrÚabstractmethodrrrrrrrr,src@seZdZejdd„ƒZdS)ÚAEADCipherContextcCsdS)z3 Authenticates the provided bytes. Nr)rrrrrÚauthenticate_additional_dataEsz.AEADCipherContext.authenticate_additional_dataN)rrrrr r"rrrrr!Csr!c@seZdZejdd„ƒZdS)ÚAEADDecryptionContextcCsdS)zŠ Returns the results of processing the final block as bytes and allows delayed passing of the authentication tag. Nr)rÚtagrrrÚfinalize_with_tagNsz'AEADDecryptionContext.finalize_with_tagN)rrrrr r%rrrrr#Lsr#c@seZdZejdd„ƒZdS)ÚAEADEncryptionContextcCsdS)zb Returns tag bytes. This is only available after encryption is finalized. Nr)rrrrr$XszAEADEncryptionContext.tagN)rrrrrr$rrrrr&Vsr&c@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) ÚCiphercCsPt|tƒstdtjƒ‚t|tƒs(tdƒ‚|dk r:| |¡||_||_ ||_ dS)Nz0Backend object does not implement CipherBackend.z&Expected interface of CipherAlgorithm.) Ú isinstancer r r ZBACKEND_MISSING_INTERFACEr Ú TypeErrorZvalidate_for_algorithmÚ algorithmÚmodeÚ_backend)rr*r+ZbackendrrrÚ__init__as   zCipher.__init__cCsBt|jtjƒr"|jjdk r"tdƒ‚|j |j|j¡}|j |ddS)Nz0Authentication tag must be None when encrypting.T)Úencrypt) r(r+r ÚModeWithAuthenticationTagr$Ú ValueErrorr,Zcreate_symmetric_encryption_ctxr*Ú _wrap_ctx)rÚctxrrrÚ encryptorrs  zCipher.encryptorcCs |j |j|j¡}|j|ddS)NF)r.)r,Zcreate_symmetric_decryption_ctxr*r+r1)rr2rrrÚ decryptor}s zCipher.decryptorcCs0t|jtjƒr$|rt|ƒSt|ƒSnt|ƒSdS)N)r(r+r r/Ú_AEADEncryptionContextÚ_AEADCipherContextÚ_CipherContext)rr2r.rrrr1ƒs  zCipher._wrap_ctxN)rrrr-r3r4r1rrrrr'`s r'c@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) r7cCs ||_dS)N)Ú_ctx)rr2rrrr-sz_CipherContext.__init__cCs|jdkrtdƒ‚|j |¡S)NzContext was already finalized.)r8rr)rrrrrr’s z_CipherContext.updatecCs |jdkrtdƒ‚|j ||¡S)NzContext was already finalized.)r8rr)rrrrrrr—s z_CipherContext.update_intocCs&|jdkrtdƒ‚|j ¡}d|_|S)NzContext was already finalized.)r8rr)rrrrrrœs   z_CipherContext.finalizeN)rrrr-rrrrrrrr7sr7c@sDeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dS)r6cCs"||_d|_d|_d|_d|_dS)NrF)r8Ú_bytes_processedÚ_aad_bytes_processedÚ_tagÚ_updated)rr2rrrr-¨s z_AEADCipherContext.__init__cCsV|jdkrtdƒ‚d|_|j|7_|j|jjjkrRtd |jjj|jjj¡ƒ‚dS)NzContext was already finalized.Tz-{0} has a maximum encrypted byte limit of {1}) r8rr<r9Ú_modeZ_MAX_ENCRYPTED_BYTESr0Úformatr)rZ data_sizerrrÚ _check_limit¯s z_AEADCipherContext._check_limitcCs| t|ƒ¡|j |¡S)N)r?Úlenr8r)rrrrrr»sz_AEADCipherContext.updatecCs| t|ƒ¡|j ||¡S)N)r?r@r8r)rrrrrrr¿sz_AEADCipherContext.update_intocCs0|jdkrtdƒ‚|j ¡}|jj|_d|_|S)NzContext was already finalized.)r8rrr$r;)rrrrrrÃs    z_AEADCipherContext.finalizecCs2|jdkrtdƒ‚|j |¡}|jj|_d|_|S)NzContext was already finalized.)r8rr%r$r;)rr$rrrrr%Ës    z$_AEADCipherContext.finalize_with_tagcCsn|jdkrtdƒ‚|jr tdƒ‚|jt|ƒ7_|j|jjjkr^td  |jjj |jjj¡ƒ‚|j  |¡dS)NzContext was already finalized.z'Update has been called on this context.z'{0} has a maximum AAD byte limit of {1}) r8rr<rr:r@r=Z_MAX_AAD_BYTESr0r>rr")rrrrrr"Ós z/_AEADCipherContext.authenticate_additional_dataN) rrrr-r?rrrr%r"rrrrr6¤s r6c@seZdZedd„ƒZdS)r5cCs|jdk rtdƒ‚|jS)Nz4You must finalize encryption before getting the tag.)r8rr;)rrrrr$æs z_AEADEncryptionContext.tagN)rrrÚpropertyr$rrrrr5äsr5) Z __future__rrrrZsixZ cryptographyrZcryptography.exceptionsrrrr r Z'cryptography.hazmat.backends.interfacesr Z&cryptography.hazmat.primitives.ciphersr Z add_metaclassÚABCMetaÚobjectr rrr!r#r&r'Zregister_interfacer7r6r5rrrrÚs6     - =