
    Ri                          d dl mZ d dlZd dlmZ d dlmZ d dlmZ	m
Z d dlmZmZ  G d de          Z G d	 d
ej        e          Z G d dej        e          ZdS )    )OptionalN)encoding)
exceptions)
PrivateKey	PublicKey)StringFixerrandomc            	           e Zd ZU dZeed<   eed<   ededededd fd            Zedefd	            Z	edefd
            Z
dS )SignedMessagezb
    A bytes subclass that holds a message that has been signed by a
    :class:`SigningKey`.
    
_signature_message	signaturemessagecombinedreturnc                 8     | |          }||_         ||_        |S N)r   r   )clsr   r   r   objs        D/srv/django_bis/venv311/lib/python3.11/site-packages/nacl/signing.py_from_partszSignedMessage._from_parts#   s$     c(mm"
    c                     | j         S )zL
        The signature contained within the :class:`SignedMessage`.
        )r   selfs    r   r   zSignedMessage.signature,   s    
 r   c                     | j         S )zJ
        The message contained within the :class:`SignedMessage`.
        )r   r   s    r   r   zSignedMessage.message3   s    
 }r   N)__name__
__module____qualname____doc__bytes__annotations__classmethodr   propertyr   r    r   r   r   r      s          
 OOO(-9>	   [ 5    X     X  r   r   c            	           e Zd ZdZej        fdedej        fdZdefdZ	de
fdZdedefd	Zdedefd
Zdej        fdedee         dej        defdZdefdZ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`
    keyencoderc                     |                     |          }t          |t                    st          j        d          t          |          t          j        j        k    r&t          j	        dt          j        j        z            || _
        d S )Nz'VerifyKey must be created from 32 bytesz%The key must be exactly %s bytes long)decode
isinstancer!   exc	TypeErrorlennaclbindingscrypto_sign_PUBLICKEYBYTES
ValueError_key)r   r(   r)   s      r   __init__zVerifyKey.__init__D   s     nnS!!#u%% 	K- IJJJs88t}???.7-:;  
 			r   r   c                     | j         S r   )r4   r   s    r   	__bytes__zVerifyKey.__bytes__T   s
    yr   c                 :    t          t          |                     S r   hashr!   r   s    r   __hash__zVerifyKey.__hash__W       E$KK   r   otherc                     t          || j                  sdS t          j                            t          |           t          |                    S NFr,   	__class__r0   r1   sodium_memcmpr!   r   r=   s     r   __eq__zVerifyKey.__eq__Z   ?    %00 	5}**5;;eEEEr   c                     | |k     S r   r%   rC   s     r   __ne__zVerifyKey.__ne___       EM""r   Nsmessager   c                    |t          |t                    s&t          j        dt          j        j        z            t          |          t          j        j        k    r&t          j        dt          j        j        z            ||	                    |          z   }n|	                    |          }t          j        
                    || j                  S )aV  
        Verifies the signature of a signed message, returning the message
        if it has not been tampered with else raising
        :class:`~nacl.exceptions.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`
        Nz4Verification signature must be created from %d bytesz+The signature must be exactly %d bytes long)r,   r!   r-   r.   r0   r1   crypto_sign_BYTESr/   r3   r+   crypto_sign_openr4   )r   rI   r   r)   s       r   verifyzVerifyKey.verifyb   s    &   i// mJm56  
 9~~!@@@nAm56  
 !7>>(#;#;;HH ~~h//H}--h	BBBr   c                 h    t           j                            | j                  }t	          |          S )z
        Converts a :class:`~nacl.signing.VerifyKey` to a
        :class:`~nacl.public.PublicKey`

        :rtype: :class:`~nacl.public.PublicKey`
        )r0   r1   $crypto_sign_ed25519_pk_to_curve25519r4   _Curve25519_PublicKey)r   raw_pks     r   to_curve25519_public_keyz"VerifyKey.to_curve25519_public_key   s)     CCDINN$V,,,r   )r   r   r   r    r   
RawEncoderr!   Encoderr5   r7   intr;   objectboolrD   rG   r   rM   rP   rR   r%   r   r   r'   r'   ;   sI         7?6I #+#3    5    !# ! ! ! !FF Ft F F F F
#F #t # # # # &*$,$7	'C 'C'C E?'C !	'C
 
'C 'C 'C 'CR-*? - - - - - -r   r'   c                       e Zd ZdZej        fdedej        fdZdefdZ	de
fdZdedefd	Zdedefd
Zedd            Zej        fdedej        defdZdefdZdS )
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.
    seedr)   c                    |                     |          }t          |t                    st          j        d          t          |          t          j        j        k    r&t          j	        dt          j        j        z            t          j        
                    |          \  }}|| _        || _        t          |          | _        d S )Nz.SigningKey must be created from a 32 byte seedz&The seed must be exactly %d bytes long)r+   r,   r!   r-   r.   r/   r0   r1   crypto_sign_SEEDBYTESr3   crypto_sign_seed_keypair_seed_signing_keyr'   
verify_key)r   rZ   r)   
public_key
secret_keys        r   r5   zSigningKey.__init__   s     ~~d##$&& 	-@  
 t99;;;.8-56  
 "&!G!G!M!M
J
&#J//r   r   c                     | j         S r   )r^   r   s    r   r7   zSigningKey.__bytes__   s
    zr   c                 :    t          t          |                     S r   r9   r   s    r   r;   zSigningKey.__hash__   r<   r   r=   c                     t          || j                  sdS t          j                            t          |           t          |                    S r?   r@   rC   s     r   rD   zSigningKey.__eq__   rE   r   c                     | |k     S r   r%   rC   s     r   rG   zSigningKey.__ne__   rH   r   c                 h     | t          t          j        j                  t          j                  S )z
        Generates a random :class:`~nacl.signing.SigningKey` object.

        :rtype: :class:`~nacl.signing.SigningKey`
        )r)   )r	   r0   r1   r\   r   rS   )r   s    r   generatezSigningKey.generate   s3     s4=677'
 
 
 	
r   r   c                 D   t           j                            || j                  }t           j        j        }|                    |d|                   }|                    ||d                   }|                    |          }t                              |||          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)r0   r1   crypto_signr_   rK   encoder   r   )r   r   r)   
raw_signedrK   r   signeds          r   signzSigningKey.sign   s     ]..w8IJJ
 M;NN:.@/@.@#ABB	..,=,>,>!?@@
++((GVDDDr   c                 l    | j         }t          j                            |          }t	          |          S )z
        Converts a :class:`~nacl.signing.SigningKey` to a
        :class:`~nacl.public.PrivateKey`

        :rtype: :class:`~nacl.public.PrivateKey`
        )r_   r0   r1   $crypto_sign_ed25519_sk_to_curve25519_Curve25519_PrivateKey)r   skraw_privates      r   to_curve25519_private_keyz$SigningKey.to_curve25519_private_key   s/     mHHLL%k222r   N)r   rY   )r   r   r   r    r   rS   r!   rT   r5   r7   rU   r;   rV   rW   rD   rG   r#   rh   r   rn   rq   rt   r%   r   r   rY   rY      sX        * %-$70 00 !0 0 0 025    !# ! ! ! !FF Ft F F F F
#F #t # # # # 	
 	
 	
 [	
 %-$7E EE !E 
	E E E E*	3+A 	3 	3 	3 	3 	3 	3r   rY   )typingr   nacl.bindingsr0   r   r   r-   nacl.publicr   rq   r   rP   
nacl.utilsr   r	   r!   r   	Encodabler'   rY   r%   r   r   <module>rz      s1                   " " " " " "        + * * * * * * *    E   BX- X- X- X- X-"K X- X- X-vd3 d3 d3 d3 d3#[ d3 d3 d3 d3 d3r   