3 L]@sddlmZmZmZddlZddlmZddlmZddl m Z m Z ddlmZmZGdddeZGd d d ejeeZGd d d ejeeZdS) )absolute_importdivisionprint_functionN)encoding) exceptions) PrivateKey PublicKey) StringFixerrandomc@s4eZdZdZeddZeddZeddZdS) SignedMessagezc A bytes subclass that holds a messaged that has been signed by a :class:`SigningKey`. cCs||}||_||_|S)N) _signature_message)cls signaturemessageZcombinedobjr0/tmp/pip-install-wfra5znf/pynacl/nacl/signing.py _from_partsszSignedMessage._from_partscCs|jS)zL The signature contained within the :class:`SignedMessage`. )r )selfrrrr&szSignedMessage.signaturecCs|jS)zJ The message contained within the :class:`SignedMessage`. )r )rrrrr-szSignedMessage.messageN) __name__ __module__ __qualname____doc__ classmethodrpropertyrrrrrrr s  r c@sVeZdZdZejfddZddZddZdd Z d d Z d ejfd dZ ddZ d S) VerifyKeyz The public key counterpart to an Ed25519 SigningKey for producing digital signatures. :param key: [:class:`bytes`] Serialized Ed25519 public key :param encoder: A class that is able to decode the `key` cCsJ|j|}t|tstjdt|tjjkr@tj dtjj||_ dS)Nz'VerifyKey must be created from 32 bytesz%The key must be exactly %s bytes long) decode isinstancebytesexc TypeErrorlennaclbindingsZcrypto_sign_PUBLICKEYBYTES ValueError_key)rkeyencoderrrr__init__>s    zVerifyKey.__init__cCs|jS)N)r&)rrrr __bytes__LszVerifyKey.__bytes__cCs tt|S)N)hashr)rrrr__hash__OszVerifyKey.__hash__cCs&t||jsdStjjt|t|S)NF)r __class__r#r$ sodium_memcmpr)rotherrrr__eq__Rs zVerifyKey.__eq__cCs ||k S)Nr)rr/rrr__ne__WszVerifyKey.__ne__NcCs*|dk r||}|j|}tjj||jS)aS Verifies the signature of a signed message, returning the message if it has not been tampered with else raising :class:`~nacl.signing.BadSignatureError`. :param smessage: [:class:`bytes`] Either the original messaged or a signature and message concated together. :param signature: [:class:`bytes`] If an unsigned message is given for smessage then the detached signature must be provided. :param encoder: A class that is able to decode the secret message and signature. :rtype: :class:`bytes` N)rr#r$Zcrypto_sign_openr&)rZsmessagerr(rrrverifyZs zVerifyKey.verifycCstjj|j}t|S)z Converts a :class:`~nacl.signing.VerifyKey` to a :class:`~nacl.public.PublicKey` :rtype: :class:`~nacl.public.PublicKey` )r#r$Z$crypto_sign_ed25519_pk_to_curve25519r&_Curve25519_PublicKey)rZraw_pkrrrto_curve25519_public_keyrsz"VerifyKey.to_curve25519_public_key) rrrrr RawEncoderr)r*r,r0r1r2r4rrrrr5src@s`eZdZdZejfddZddZddZdd Z d d Z e d d Z ejfddZ ddZdS) SigningKeya Private key for producing digital signatures using the Ed25519 algorithm. Signing keys are produced from a 32-byte (256-bit) random seed value. This value can be passed into the :class:`~nacl.signing.SigningKey` as a :func:`bytes` whose length is 32. .. warning:: This **must** be protected and remain secret. Anyone who knows the value of your :class:`~nacl.signing.SigningKey` or it's seed can masquerade as you. :param seed: [:class:`bytes`] Random 32-byte value (i.e. private key) :param encoder: A class that is able to decode the seed :ivar: verify_key: [:class:`~nacl.signing.VerifyKey`] The verify (i.e. public) key that corresponds with this signing key. cCsj|j|}t|tstjdt|tjjkr@tj dtjjtjj |\}}||_ ||_ t ||_dS)Nz.SigningKey must be created from a 32 byte seedz&The seed must be exactly %d bytes long)rrrr r!r"r#r$crypto_sign_SEEDBYTESr%Zcrypto_sign_seed_keypair_seed _signing_keyrZ verify_key)rseedr(Z public_keyZ secret_keyrrrr)s   zSigningKey.__init__cCs|jS)N)r8)rrrrr*szSigningKey.__bytes__cCs tt|S)N)r+r)rrrrr,szSigningKey.__hash__cCs&t||jsdStjjt|t|S)NF)rr-r#r$r.r)rr/rrrr0s zSigningKey.__eq__cCs ||k S)Nr)rr/rrrr1szSigningKey.__ne__cCs|ttjjtjdS)z Generates a random :class:`~nacl.signing.SigningKey` object. :rtype: :class:`~nacl.signing.SigningKey` )r()r r#r$r7rr5)rrrrgenerates zSigningKey.generatecCsTtjj||j}tjj}|j|d|}|j||d}|j|}tj|||S)z Sign a message using this key. :param message: [:class:`bytes`] The data to be signed. :param encoder: A class that is used to encode the signed message. :rtype: :class:`~nacl.signing.SignedMessage` N)r#r$Z crypto_signr9crypto_sign_BYTESencoder r)rrr(Z raw_signedr<rsignedrrrsigns  zSigningKey.signcCs|j}tjj|}t|S)z Converts a :class:`~nacl.signing.SigningKey` to a :class:`~nacl.public.PrivateKey` :rtype: :class:`~nacl.public.PrivateKey` )r9r#r$Z$crypto_sign_ed25519_sk_to_curve25519_Curve25519_PrivateKey)rskZ raw_privaterrrto_curve25519_private_keys z$SigningKey.to_curve25519_private_keyN)rrrrrr5r)r*r,r0r1rr;r?rBrrrrr6}s r6) __future__rrrZ nacl.bindingsr#rrr Z nacl.publicrr@rr3Z nacl.utilsr r rr Z Encodableobjectrr6rrrrs  H