a °…b”"ã@sjUddlmZmZddlmZddlmZmZddl m Z e  ¡Z e ed<e ¡Ze ed<e ¡Ze ed<e ¡Ze ed<e ¡Ze ed <e ¡Ze ed <e ¡Ze ed <e ¡Ze ed <e ¡Ze ed <dZdZ e e!e!e!ddœdd„Z"e dddfe!e e!e!e!e!dœdd„Z#edddZ$Gdd„dƒZ%ddde fe!e!e!e e%dœdd„Z&e%e!ddœd d!„Z'e%e!d"œd#d$„Z(dS)%é)ÚNoReturnÚTypeVar)Ú exceptions)ÚffiÚlib)ÚensureÚcrypto_generichash_BYTESÚcrypto_generichash_BYTES_MINÚcrypto_generichash_BYTES_MAXÚcrypto_generichash_KEYBYTESÚcrypto_generichash_KEYBYTES_MINÚcrypto_generichash_KEYBYTES_MAXÚcrypto_generichash_SALTBYTESÚ crypto_generichash_PERSONALBYTESÚcrypto_generichash_STATEBYTESz!{0} length greater than {1} bytesz{0} greater than {1}N)Ú digest_sizeÚkeyÚsaltÚpersonÚreturncCsØtt|tƒdtjdtt|tƒdtjdtt|tƒdtjdtt|tƒdtjdt|tkt dt¡tj dtt |ƒt kt  dt ¡tj dtt |ƒt kt  dt ¡tj dtt |ƒtkt  d t¡tj dd S) zCheck hash parameterszKey must be a bytes sequence©ZraisingzSalt must be a bytes sequencezPerson must be a bytes sequencez%Digest size must be an integer numberZ Digest_sizeÚKeyZSaltZPersonN)rÚ isinstanceÚbytesÚexcÚ TypeErrorÚintr Ú_TOOBIGÚformatÚ ValueErrorÚlenr Ú _OVERLONGrr)rrrr©r"úG/tmp/pip-target-98j97qn4/lib/python/nacl/bindings/crypto_generichash.pyÚ _checkparams)sPýýýý ý  ý  ý  ýr$ó)Údatarrrrrc Cs´t||||ƒtt|tƒdtjdt d|¡}t dt¡}t dt ¡}t  ||t |ƒ¡t  ||t |ƒ¡t   |||t |ƒ|t |ƒ||¡}t|dkdtjdt ||¡dd…S)abOne shot hash interface :param data: the input data to the hash function :type data: 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 :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 []rúUnexpected failureN)r$rrrrrrÚnewrrÚmemmover rZ(crypto_generichash_blake2b_salt_personalÚ RuntimeErrorÚbuffer) r&rrrrÚdigestÚ_saltÚ_personÚrcr"r"r#Ú!generichash_blake2b_salt_personal^s ý   ÿr3Ú _Blake2StateÚ Blake2State)Úboundc@sDeZdZdZddgZedœdd„Zedœdd „Ze e d œd d „Z d S)r5zN Python-level wrapper for the crypto_generichash_blake2b state buffer Ú _statebufr)rcCst dt¡|_||_dS)Nr()rr+rr7r)Úselfrr"r"r#Ú__init__ sÿzBlake2State.__init__)rcCstd |jj¡ƒ‚dS)zc Raise the same exception as hashlib's blake implementation on copy.copy() zcan't pickle {} objectsN)rrÚ __class__Ú__name__)r8r"r"r#Ú __reduce__¦s ÿzBlake2State.__reduce__)r8rcCs"| |j¡}t |j|jt¡|S)N)r:rrr,r7r)r8Z_str"r"r#Úcopy¯s   ÿzBlake2State.copyN) r;Ú __module__Ú __qualname__Ú__doc__Ú __slots__rr9rr<r4r=r"r"r"r#r5™s  )rrrrrcCs„t||||ƒt|ƒ}t dt¡}t dt¡}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)r$r5rr+rrr,r rZ-crypto_generichash_blake2b_init_salt_personalr7rrr-)rrrrÚstater0r1r2r"r"r#Úgenerichash_blake2b_init·s  ÿrC)rBr&rcCsXtt|tƒdtjdtt|tƒdtjdt |j|t |ƒ¡}t|dkdtj ddS)zúUpdate 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 objectrr'rr*N) rrr5rrrrZ!crypto_generichash_blake2b_updater7r r-)rBr&r2r"r"r#Úgenerichash_blake2b_updateçs ýý ÿrE)rBrcCs^tt|tƒdtjdt dt¡}t  |j ||j ¡}t|dkdtj dt  ||j ¡dd…S)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 rDrr(rr*N)rrr5rrrr+r rZ crypto_generichash_blake2b_finalr7rr-r.)rBZ_digestr2r"r"r#Úgenerichash_blake2b_finals ý  ÿrF))ÚtypingrrZnaclrrZ nacl._sodiumrrZnacl.exceptionsrZ crypto_generichash_blake2b_bytesrrÚ__annotations__Z$crypto_generichash_blake2b_bytes_minr Z$crypto_generichash_blake2b_bytes_maxr Z#crypto_generichash_blake2b_keybytesr Z'crypto_generichash_blake2b_keybytes_minr Z'crypto_generichash_blake2b_keybytes_maxr Z$crypto_generichash_blake2b_saltbytesrZ(crypto_generichash_blake2b_personalbytesrZcrypto_generichash_statebytesrr!rrr$r3r4r5rCrErFr"r"r"r#Ús^  ÿ ÿ ÿ þ 7ûú 8 üû 0