U q`@sddlmZmZmZddlmZddlmZm Z ddl m Z ddddd d d gZ e Ze Ze Ze Zd dZd dZddZddZdS))absolute_importdivisionprint_function) exceptions)ffilib)ensurecrypto_kx_keypaircrypto_kx_client_session_keyscrypto_kx_server_session_keyscrypto_kx_PUBLIC_KEY_BYTEScrypto_kx_SECRET_KEY_BYTEScrypto_kx_SEED_BYTEScrypto_kx_SESSION_KEY_BYTEScCs`tdt}tdt}t||}t|dkdtjdt |tddt |tddfS)z Generate a keypair. This is a duplicate crypto_box_keypair, but is included for api consistency. :return: (public_key, secret_key) :rtype: (bytes, bytes) unsigned char[]rKey generation failed.ZraisingN) rnewr r rr rexc CryptoErrorbuffer) public_key secret_keyresr>/tmp/pip-target-nv4zd3e_/lib/python/nacl/bindings/crypto_kx.pyr &s   cCstdt}tdt}tt|to.t|tkd tt j dt |||}t|dkdt jdt|tddt|tddfS)ag Generate a keypair with a given seed. This is functionally the same as crypto_box_seed_keypair, however it uses the blake2b hash primitive instead of sha512. It is included mainly for api consistency when using crypto_kx. :param seed: random seed :type seed: bytes :return: (public_key, secret_key) :rtype: (bytes, bytes) rz+Seed must be a {0} byte long bytes sequencerrrN)rrr r r isinstancebyteslenrformatr TypeErrorrcrypto_kx_seed_keypairrr)seedrrrrrrr!7s    r!cCstt|tot|tkdttjdtt|to>t|tkdttjdtt|toft|tkdttjdt dt }t dt }t |||||}t|dkdtjdt |t ddt |t ddfS) a+ Generate session keys for the client. :param client_public_key: :type client_public_key: bytes :param client_secret_key: :type client_secret_key: bytes :param server_public_key: :type server_public_key: bytes :return: (rx_key, tx_key) :rtype: (bytes, bytes) 9Client public key must be a {0} bytes long bytes sequencerz9Client secret key must be a {0} bytes long bytes sequence9Server public key must be a {0} bytes long bytes sequencerrz%Client session key generation failed.N)rrrrr rrr r rrrrr rr)client_public_keyZclient_secret_keyserver_public_keyrx_keytx_keyrrrrr PsH        cCstt|tot|tkdttjdtt|to>t|tkdttjdtt|toft|tkdttjdt dt }t dt }t |||||}t|dkdtjdt |t ddt |t ddfS) a+ Generate session keys for the server. :param server_public_key: :type server_public_key: bytes :param server_secret_key: :type server_secret_key: bytes :param client_public_key: :type client_public_key: bytes :return: (rx_key, tx_key) :rtype: (bytes, bytes) r$rz9Server secret key must be a {0} bytes long bytes sequencer#rrz%Server session key generation failed.N)rrrrr rrr r rrrrr rr)r&Zserver_secret_keyr%r'r(rrrrr }sH        N) __future__rrrZnaclrrZ nacl._sodiumrrZnacl.exceptionsr__all__Zcrypto_kx_publickeybytesr Zcrypto_kx_secretkeybytesr Zcrypto_kx_seedbytesrZcrypto_kx_sessionkeybytesrr r!r r rrrrs&   -