U q`"@sddlmZmZmZddlmZddlmZddl m Z m Z ddl m Z e Ze Ze Ze Ze Ze Ze Ze Ze ZdZ dZ!dd Z"ed d d fd d Z#Gd dde$Z%d d d efddZ&ddZ'ddZ(dS))absolute_importdivisionprint_function) integer_types) exceptions)ffilib)ensurez!{0} length greater than {1} bytesz{0} greater than {1}cCstt|tdtjdtt|tdtjdtt|tdtjdtt|tdtjdt|tktdttj dtt |t kt dt tj dtt |t kt dt tj dtt |tkt d ttj dd S) zCheck hash paramterszKey must be a bytes sequenceZraisingzSalt must be a bytes sequencezPerson must be a bytes sequencez%Digest size must be an integer numberZ Digest_sizeZKeyZSaltZPersonN)r isinstancebytesexc TypeErrorrcrypto_generichash_BYTES_MAX_TOOBIGformat ValueErrorlencrypto_generichash_KEYBYTES_MAX _OVERLONGcrypto_generichash_SALTBYTES crypto_generichash_PERSONALBYTES) digest_sizekeysaltpersonrG/tmp/pip-target-nv4zd3e_/lib/python/nacl/bindings/crypto_generichash.py _checkparams's@           rc Cst||||tt|tdtjdtd|}tdt}tdt }t ||t |t ||t |t |||t ||t |||}t|dkdtjdt||ddS)aLOne shot hash interface :param data: the input data to the hash function :param digest_size: must be at most :py:data:`.crypto_generichash_BYTES_MAX`; the default digest size is :py:data:`.crypto_generichash_BYTES` :type digest_size: int :param key: must be at most :py:data:`.crypto_generichash_KEYBYTES_MAX` long :type key: bytes :param salt: must be at most :py:data:`.crypto_generichash_SALTBYTES` long; will be zero-padded if needed :type salt: bytes :param person: must be at most :py:data:`.crypto_generichash_PERSONALBYTES` long: will be zero-padded if needed :type person: bytes :return: digest_size long digest :rtype: bytes #Input data must be a bytes sequencer unsigned char[]unsigned char []rUnexpected failureN)rr r r r rrnewrrmemmoverrZ(crypto_generichash_blake2b_salt_personal RuntimeErrorbuffer) datarrrrdigest_salt_personrcrrr!generichash_blake2b_salt_personalJs,     r-c@s0eZdZdZddgZddZddZdd Zd S) Blake2StatezN Python-level wrapper for the crypto_generichash_blake2b state buffer _statebufrcCstdt|_||_dS)Nr!)rr$crypto_generichash_STATEBYTESr/r)selfrrrr__init__szBlake2State.__init__cCstd|jjdS)zc Raise the same exception as hashlib's blake implementation on copy.copy() zcan't pickle {} objectsN)rr __class____name__)r1rrr __reduce__szBlake2State.__reduce__cCs"||j}t|j|jt|S)N)r3rrr%r/r0)r1Z_strrrcopys  zBlake2State.copyN)r4 __module__ __qualname____doc__ __slots__r2r5r6rrrrr.}s r.cCst||||t|}tdt}tdt}t||t|t||t|t |j |t||||}t |dkdt j d|S)a@ Create a new initialized blake2b hash state :param key: must be at most :py:data:`.crypto_generichash_KEYBYTES_MAX` long :type key: bytes :param salt: must be at most :py:data:`.crypto_generichash_SALTBYTES` long; will be zero-padded if needed :type salt: bytes :param person: must be at most :py:data:`.crypto_generichash_PERSONALBYTES` long: will be zero-padded if needed :type person: bytes :param digest_size: must be at most :py:data:`.crypto_generichash_BYTES_MAX`; the default digest size is :py:data:`.crypto_generichash_BYTES` :type digest_size: int :return: a initialized :py:class:`.Blake2State` :rtype: object r"rr#r )rr.rr$rrr%rrZ-crypto_generichash_blake2b_init_salt_personalr/r r r&)rrrrstater*r+r,rrrgenerichash_blake2b_inits"   r<cCsXtt|tdtjdtt|tdtjdt|j|t |}t|dkdtj ddS)zUpdate the blake2b hash state :param state: a initialized Blake2bState object as returned from :py:func:`.crypto_generichash_blake2b_init` :type state: :py:class:`.Blake2State` :param data: :type data: bytes "State must be a Blake2State objectr r rr#N) r r r.r rr rZ!crypto_generichash_blake2b_updater/rr&)r;r(r,rrrgenerichash_blake2b_updates   r>cCs^tt|tdtjdtdt}t |j ||j }t|dkdtj dt ||j ddS)a:Finalize the blake2b hash state and return the digest. :param state: a initialized Blake2bState object as returned from :py:func:`.crypto_generichash_blake2b_init` :type state: :py:class:`.Blake2State` :return: the blake2 digest of the passed-in data stream :rtype: bytes r=r r!rr#N)r r r.r rrr$rrZ crypto_generichash_blake2b_finalr/rr&r')r;Z_digestr,rrrgenerichash_blake2b_finals   r?N)) __future__rrrsixrZnaclrr Z nacl._sodiumrrZnacl.exceptionsr Z crypto_generichash_blake2b_bytesZcrypto_generichash_BYTESZ$crypto_generichash_blake2b_bytes_minZcrypto_generichash_BYTES_MINZ$crypto_generichash_blake2b_bytes_maxrZ#crypto_generichash_blake2b_keybytesZcrypto_generichash_KEYBYTESZ'crypto_generichash_blake2b_keybytes_minZcrypto_generichash_KEYBYTES_MINZ'crypto_generichash_blake2b_keybytes_maxrZ$crypto_generichash_blake2b_saltbytesrZ(crypto_generichash_blake2b_personalbytesrZcrypto_generichash_statebytesr0rrrr-objectr.r<r>r?rrrrs:   $ 3 /