3 lá˜_«ã@s‚ddlmZmZmZddlZddlZddlmZddlm Z m Z m Z ddl m Z ddlmZejejƒGdd„deƒƒZejejƒGd d „d eƒƒZejejƒGd d „d eƒƒZejeƒGd d„deƒƒZejeƒGdd„deƒƒZejeƒGdd„deƒƒZejeƒGdd„deƒƒZejeƒGdd„deƒƒZejeƒGdd„deƒƒZejeƒGdd„deƒƒZejeƒGdd„deƒƒZejeƒGdd„deƒƒZejeƒGdd „d eƒƒZ ejeƒGd!d"„d"eƒƒZ!ejeƒGd#d$„d$eƒƒZ"ejeƒejeƒGd%d&„d&eƒƒƒZ#ejeƒejeƒGd'd(„d(eƒƒƒZ$ejeƒGd)d*„d*eƒƒZ%ejeƒGd+d,„d,eƒƒZ&ejeƒGd-d.„d.eƒƒZ'dS)/é)Úabsolute_importÚdivisionÚprint_functionN)Úutils)ÚAlreadyFinalizedÚUnsupportedAlgorithmÚ_Reasons)Ú _get_backend)Ú HashBackendc@s(eZdZejdd„ƒZejdd„ƒZdS)Ú HashAlgorithmcCsdS)zH A string naming this algorithm (e.g. "sha256", "md5"). N©)Úselfr r ú/usr/lib64/python3.6/hashes.pyÚnameszHashAlgorithm.namecCsdS)z< The size of the resulting digest in bytes. Nr )r r r rÚ digest_sizeszHashAlgorithm.digest_sizeN)Ú__name__Ú __module__Ú __qualname__ÚabcÚabstractpropertyrrr r r rr sr c@sDeZdZejdd„ƒZejdd„ƒZejdd„ƒZejdd„ƒZ d S) Ú HashContextcCsdS)zD A HashAlgorithm that will be used by this context. Nr )r r r rÚ algorithm&szHashContext.algorithmcCsdS)z@ Processes the provided bytes through the hash. Nr )r Údatar r rÚupdate,szHashContext.updatecCsdS)zR Finalizes the hash context and returns the hash digest as bytes. Nr )r r r rÚfinalize2szHashContext.finalizecCsdS)zM Return a HashContext that is a copy of the current context. Nr )r r r rÚcopy8szHashContext.copyN) rrrrrrÚabstractmethodrrrr r r rr$src@seZdZdZdS)ÚExtendableOutputFunctionz7 An interface for extendable output functions. N)rrrÚ__doc__r r r rr?src@s8eZdZd dd„ZejdƒZdd„Zdd„Zd d „Z dS) ÚHashNcCs`t|ƒ}t|tƒstdtjƒ‚t|tƒs0tdƒ‚||_||_ |dkrV|j j |j ƒ|_ n||_ dS)Nz.Backend object does not implement HashBackend.z*Expected instance of hashes.HashAlgorithm.) r Ú isinstancer rrZBACKEND_MISSING_INTERFACEr Ú TypeErrorÚ _algorithmÚ_backendZcreate_hash_ctxrÚ_ctx)r rÚbackendÚctxr r rÚ__init__Hs  z Hash.__init__r"cCs.|jdkrtdƒ‚tjd|ƒ|jj|ƒdS)NzContext was already finalized.r)r$rrZ_check_bytesliker)r rr r rr]s  z Hash.updatecCs*|jdkrtdƒ‚t|j|j|jjƒdS)NzContext was already finalized.)r%r&)r$rrrr#r)r r r rrcs z Hash.copycCs&|jdkrtdƒ‚|jjƒ}d|_|S)NzContext was already finalized.)r$rr)r Zdigestr r rrjs   z Hash.finalize)NN) rrrr'rÚread_only_propertyrrrrr r r rrFs   rc@seZdZdZdZdZdS)ÚSHA1Zsha1éé@N)rrrrrÚ block_sizer r r rr)rsr)c@seZdZdZdZdZdS)Ú SHA512_224z sha512-224éé€N)rrrrrr,r r r rr-ysr-c@seZdZdZdZdZdS)Ú SHA512_256z sha512-256é r/N)rrrrrr,r r r rr0€sr0c@seZdZdZdZdZdS)ÚSHA224Zsha224r.r+N)rrrrrr,r r r rr2‡sr2c@seZdZdZdZdZdS)ÚSHA256Zsha256r1r+N)rrrrrr,r r r rr3Žsr3c@seZdZdZdZdZdS)ÚSHA384Zsha384é0r/N)rrrrrr,r r r rr4•sr4c@seZdZdZdZdZdS)ÚSHA512Zsha512r+r/N)rrrrrr,r r r rr6œsr6c@seZdZdZdZdS)ÚSHA3_224zsha3-224r.N)rrrrrr r r rr7£sr7c@seZdZdZdZdS)ÚSHA3_256zsha3-256r1N)rrrrrr r r rr8©sr8c@seZdZdZdZdS)ÚSHA3_384zsha3-384r5N)rrrrrr r r rr9¯sr9c@seZdZdZdZdS)ÚSHA3_512zsha3-512r+N)rrrrrr r r rr:µsr:c@s"eZdZdZdd„ZejdƒZdS)ÚSHAKE128Zshake128cCs.t|tjƒstdƒ‚|dkr$tdƒ‚||_dS)Nzdigest_size must be an integeréz&digest_size must be a positive integer)r ÚsixÚ integer_typesr!Ú ValueErrorÚ _digest_size)r rr r rr'Às  zSHAKE128.__init__r@N)rrrrr'rr(rr r r rr;»s r;c@s"eZdZdZdd„ZejdƒZdS)ÚSHAKE256Zshake256cCs.t|tjƒstdƒ‚|dkr$tdƒ‚||_dS)Nzdigest_size must be an integerr<z&digest_size must be a positive integer)r r=r>r!r?r@)r rr r rr'Ñs  zSHAKE256.__init__r@N)rrrrr'rr(rr r r rrAÌs rAc@seZdZdZdZdZdS)ÚMD5Zmd5ér+N)rrrrrr,r r r rrBÝsrBc@s.eZdZdZdZdZdZdd„Zej dƒZ dS) ÚBLAKE2bZblake2br+r<r/cCs|dkrtdƒ‚||_dS)Nr+zDigest size must be 64)r?r@)r rr r rr'ëszBLAKE2b.__init__r@N) rrrrÚ_max_digest_sizeÚ_min_digest_sizer,r'rr(rr r r rrDäs rDc@s.eZdZdZdZdZdZdd„Zej dƒZ dS) ÚBLAKE2sZblake2sr+r1r<cCs|dkrtdƒ‚||_dS)Nr1zDigest size must be 32)r?r@)r rr r rr'üszBLAKE2s.__init__r@N) rrrrr,rErFr'rr(rr r r rrGõs rG)(Z __future__rrrrr=Z cryptographyrZcryptography.exceptionsrrrZcryptography.hazmat.backendsr Z'cryptography.hazmat.backends.interfacesr Z add_metaclassÚABCMetaÚobjectr rrZregister_interfacerr)r-r0r2r3r4r6r7r8r9r:r;rArBrDrGr r r rÚs`   +