3 L]J@sddlmZmZmZddlmZddlmZddl m Z m Z ddl m Z e jZe jZe jZe jZe jZe jZe jZe jZe jZdZ dZ!dd Z"ed d d fd d Z#d d d efd dZ$ddZ%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|tktjdttj dtt |t kt jdt tj dtt |t kt jdt tj dtt |tkt jd ttj dd S) zCheck hash paramterszKey must be a bytes sequence)raisingzSalt 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_sizekeysaltpersonrD/tmp/pip-install-wfra5znf/pynacl/nacl/bindings/crypto_generichash.py _checkparams's0                  rc Cst||||tt|tdtjdtjd|}tjdt}tjdt }tj ||t |tj ||t |t j |||t ||t |||}t|dkdtjdtj||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 z#Input data must be a bytes sequence)r zunsigned char[]zunsigned char []rzUnexpected failureN)rr r r r rrnewrrmemmoverrZ(crypto_generichash_blake2b_salt_personal RuntimeErrorbuffer) datarrrrdigest_salt_personrcrrr!generichash_blake2b_salt_personalJs        r)cCst||||tjdt}tjdt}tjdt}tj||t|tj||t|tj ||t||||}t |dkdt j d|S)a7 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: an initizialized state buffer :rtype: object zunsigned char[]zunsigned char []rzUnexpected failure)r ) rrr crypto_generichash_STATEBYTESrrr!rrZ-crypto_generichash_blake2b_init_salt_personalr r r")rrrrstatebufr&r'r(rrrgenerichash_blake2b_init}s     r,cCs@tt|tdtjdtj||t|}t|dkdtjddS)zUpdate the blake2b hash state :param statebuf: an initialized blake2b state buffer as returned from :py:func:`.crypto_generichash_blake2b_init` :type statebuf: object :param data: :type data: bytes z#Input data must be a bytes sequence)r rzUnexpected failureN) r r r r rrZ!crypto_generichash_blake2b_updaterr")r+r$r(rrrgenerichash_blake2b_updates   r-cCsBtjdt}tj|||}t|dkdtjdtj||ddS)zFinalize the blake2b hash state and return the digest. :param statebuf: :type statebuf: object :param digest_size: :type digest_size: int :return: the blake2 digest of the passed-in data stream :rtype: bytes zunsigned char[]rzUnexpected failure)r N) rr rrZ crypto_generichash_blake2b_finalr r r"r#)r+rZ_digestr(rrrgenerichash_blake2b_finals   r.cCstjdt}tj||t|S)z-Return a copy of the given blake2b hash statezunsigned char[])rr r*r!)r+Znewstaterrrgenerichash_blake2b_state_copys 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_statebytesr*rrrr)r,r-r.r/rrrrs0   $1 -