<s> from __future__ import absolute_import , division , print_function <EOL> import abc <EOL> import six <EOL> from cryptography import utils <EOL> from cryptography . exceptions import ( <EOL> AlreadyFinalized , UnsupportedAlgorithm , _Reasons <EOL> ) <EOL> from cryptography . hazmat . backends . interfaces import HashBackend <EOL> @ six . add_metaclass ( abc . ABCMeta ) <EOL> class HashAlgorithm ( object ) : <EOL> @ abc . abstractproperty <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> @ abc . abstractproperty <EOL> def digest_size ( self ) : <EOL> """<STR_LIT>""" <EOL> @ abc . abstractproperty <EOL> def block_size ( self ) : <EOL> """<STR_LIT>""" <EOL> @ six . add_metaclass ( abc . ABCMeta ) <EOL> class HashContext ( object ) : <EOL> @ abc . abstractproperty <EOL> def algorithm ( self ) : <EOL> """<STR_LIT>""" <EOL> @ abc . abstractmethod <EOL> def update ( self , data ) : <EOL> """<STR_LIT>""" <EOL> @ abc . abstractmethod <EOL> def finalize ( self ) : <EOL> """<STR_LIT>""" <EOL> @ abc . abstractmethod <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> @ utils . register_interface ( HashContext ) <EOL> class Hash ( object ) : <EOL> def __init__ ( self , algorithm , backend , ctx = None ) : <EOL> if not isinstance ( backend , HashBackend ) : <EOL> raise UnsupportedAlgorithm ( <EOL> "<STR_LIT>" , <EOL> _Reasons . BACKEND_MISSING_INTERFACE <EOL> ) <EOL> if not isinstance ( algorithm , HashAlgorithm ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> self . _algorithm = algorithm <EOL> self . _backend = backend <EOL> if ctx is None : <EOL> self . _ctx = self . _backend . create_hash_ctx ( self . algorithm ) <EOL> else : <EOL> self . _ctx = ctx <EOL> algorithm = utils . read_only_property ( "<STR_LIT>" ) <EOL> def update ( self , data ) : <EOL> if self . _ctx is None : <EOL> raise AlreadyFinalized ( "<STR_LIT>" ) <EOL> if not isinstance ( data , bytes ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> self . _ctx . update ( data ) <EOL> def copy ( self ) : <EOL> if self . _ctx is None : <EOL> raise AlreadyFinalized ( "<STR_LIT>" ) <EOL> return Hash ( <EOL> self . algorithm , backend = self . _backend , ctx = self . _ctx . copy ( ) <EOL> ) <EOL> def finalize ( self ) : <EOL> if self . _ctx is None : <EOL> raise AlreadyFinalized ( "<STR_LIT>" ) <EOL> digest = self . _ctx . finalize ( ) <EOL> self . _ctx = None <EOL> return digest <EOL> @ utils . register_interface ( HashAlgorithm ) <EOL> class SHA1 ( object ) : <EOL> name = "<STR_LIT>" <EOL> digest_size = <NUM_LIT:20> <EOL> block_size = <NUM_LIT:64> <EOL> @ utils . register_interface ( HashAlgorithm ) <EOL> class SHA224 ( object ) : <EOL> name = "<STR_LIT>" <EOL> digest_size = <NUM_LIT> <EOL> block_size = <NUM_LIT:64> <EOL> @ utils . register_interface ( HashAlgorithm ) <EOL> class SHA256 ( object ) : <EOL> name = "<STR_LIT>" <EOL> digest_size = <NUM_LIT:32> <EOL> block_size = <NUM_LIT:64> <EOL> @ utils . register_interface ( HashAlgorithm ) <EOL> class SHA384 ( object ) : <EOL> name = "<STR_LIT>" <EOL> digest_size = <NUM_LIT> <EOL> block_size = <NUM_LIT> <EOL> @ utils . register_interface ( HashAlgorithm ) <EOL> class SHA512 ( object ) : <EOL> name = "<STR_LIT>" <EOL> digest_size = <NUM_LIT:64> <EOL> block_size = <NUM_LIT> <EOL> @ utils . register_interface ( HashAlgorithm ) <EOL> class RIPEMD160 ( object ) : <EOL> name = "<STR_LIT>" <EOL> digest_size = <NUM_LIT:20> <EOL> block_size = <NUM_LIT:64> <EOL> @ utils . register_interface ( HashAlgorithm ) <EOL> class Whirlpool ( object ) : <EOL> name = "<STR_LIT>" <EOL> digest_size = <NUM_LIT:64> <EOL> block_size = <NUM_LIT:64> <EOL> @ utils . register_interface ( HashAlgorithm ) <EOL> class MD5 ( object ) : <EOL> name = "<STR_LIT>" <EOL> digest_size = <NUM_LIT:16> <EOL> block_size = <NUM_LIT:64> </s>
