
    7g9                     D   d dl mZmZmZmZmZ d dlZd dlmZ d dlm	Z
 d dlmZ d dlmZmZmZ  G d dej        e          Z G d	 d
ej        e          Z edd          Z G d dej        e          Z edee          Z G d dee         ej        e          ZdS )    )ClassVarGenericOptionalTypeTypeVarN)encoding)
exceptions)Encoder)EncryptedMessageStringFixerrandomc                       e Zd ZU dZej        j        Zee	         e
d<   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S )	PublicKeya=  
    The public key counterpart to an Curve25519 :class:`nacl.public.PrivateKey`
    for encrypting messages.

    :param public_key: [:class:`bytes`] Encoded Curve25519 public key
    :param encoder: A class that is able to decode the `public_key`

    :cvar SIZE: The size that the public key is required to be
    SIZE
public_keyencoderc                 (   |                     |          | _        t          | j        t                    st	          j        d          t          | j                  | j        k    r,t	          j        d	                    | j                            d S )Nz'PublicKey must be created from 32 bytesz,The public key must be exactly {} bytes long)
decode_public_key
isinstancebytesexc	TypeErrorlenr   
ValueErrorformat)selfr   r   s      E/var/www/html/syslog/venv/lib/python3.11/site-packages/nacl/public.py__init__zPublicKey.__init__$   s    
 #>>*55$*E22 	K- IJJJt  DI--.>EEI    .-    returnc                     | j         S Nr   r   s    r   	__bytes__zPublicKey.__bytes__4       r    c                 :    t          t          |                     S r#   )hashr   r%   s    r   __hash__zPublicKey.__hash__7   s    E$KK   r    otherc                     t          || j                  sdS t          j                            t          |           t          |                    S NF)r   	__class__naclbindingssodium_memcmpr   r   r+   s     r   __eq__zPublicKey.__eq__:   s?    %00 	5}**5;;eEEEr    c                     | |k     S r#    r2   s     r   __ne__zPublicKey.__ne__?       EM""r    N)__name__
__module____qualname____doc__r/   r0   crypto_box_PUBLICKEYBYTESr   r   int__annotations__r   
RawEncoderr   r
   r   r&   r*   objectboolr3   r6   r5   r    r   r   r      s           -AD(3-AAA
 %-$7  !     5        !# ! ! ! !FF Ft F F F F
#F #t # # # # # #r    r   c                   $   e Zd ZU dZej        j        Zee	         e
d<   ej        j        Zee	         e
d<   ej        fdedej        fdZeej        fdedej        dd 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dS )
PrivateKeya{  
    Private key for decrypting messages using the Curve25519 algorithm.

    .. warning:: This **must** be protected and remain secret. Anyone who
        knows the value of your :class:`~nacl.public.PrivateKey` can decrypt
        any message encrypted by the corresponding
        :class:`~nacl.public.PublicKey`

    :param private_key: The private key used to decrypt messages
    :param encoder: The encoder class used to decode the given keys

    :cvar SIZE: The size that the private key is required to be
    :cvar SEED_SIZE: The size that the seed used to generate the
                     private key is required to be
    r   	SEED_SIZEprivate_keyr   c                 V   |                     |          }t          |t                    rt          |          | j        k    s,t          j        d                    | j                            t          j	        
                    |          }|| _        t          |          | _        d S )Nz>PrivateKey must be created from a {} bytes long raw secret key)r   r   r   r   r   r   r   r   r/   r0   crypto_scalarmult_base_private_keyr   r   )r   rE   r   raw_public_keys       r   r   zPrivateKey.__init__W   s     nn[11 {E**	/2;/?/?49/L/L-0&##	   ==kJJ'#N33r    seedr!   c                 8   |                     |          }t          |t                    rt          |          | j        k    s,t          j        d                    | j                            t          j	        
                    |          \  }} | |          S )ah  
        Generate a PrivateKey using a deterministic construction
        starting from a caller-provided seed

        .. warning:: The seed **must** be high-entropy; therefore,
            its generator **must** be a cryptographic quality
            random function like, for example, :func:`~nacl.utils.random`.

        .. warning:: The seed **must** be protected and remain secret.
            Anyone who knows the seed is really in possession of
            the corresponding PrivateKey.

        :param seed: The seed used to generate the private key
        :rtype: :class:`~nacl.public.PrivateKey`
        z7PrivateKey seed must be a {} bytes long binary sequence)r   r   r   r   rD   r   r   r   r/   r0   crypto_box_seed_keypair)clsrJ   r   raw_pkraw_sks        r   	from_seedzPrivateKey.from_seedn   s    , ~~d##4'' 	CII,F,F-&&''	   >>tDDs6{{r    c                     | j         S r#   )rH   r%   s    r   r&   zPrivateKey.__bytes__   s      r    c                 b    t          t          |           t          | j                  f          S r#   )r)   typer   r   r%   s    r   r*   zPrivateKey.__hash__   s%    T$ZZt!7!78999r    r+   c                 P    t          || j                  sdS | j        |j        k    S r-   )r   r.   r   r2   s     r   r3   zPrivateKey.__eq__   s+    %00 	5%"222r    c                     | |k     S r#   r5   r2   s     r   r6   zPrivateKey.__ne__   r7   r    c                 ^     | t          t          j                  t          j                  S )z~
        Generates a random :class:`~nacl.public.PrivateKey` object

        :rtype: :class:`~nacl.public.PrivateKey`
        r   )r   rC   r   r   r?   )rM   s    r   generatezPrivateKey.generate   s&     s6*/**H4GHHHHr    N)r!   rC   )r8   r9   r:   r;   r/   r0   crypto_box_SECRETKEYBYTESr   r   r=   r>   crypto_box_SEEDBYTESrD   r   r?   r   r
   r   classmethodrP   r&   r*   r@   rA   r3   r6   rX   r5   r    r   rC   rC   C   sw           -AD(3-AAA#}AIx}AAA
 %-$74 44 !4 4 4 4.  %-$7! !! !! 
	! ! ! [!F!5 ! ! ! !:# : : : :3F 3t 3 3 3 3
#F #t # # # # I I I [I I Ir    rC   _BoxBox)boundc            
       2   e Zd ZU dZej        j        Zee	         e
d<   ee
d<   dedefdZdefdZeej        fd	ee         d
e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j        fdedee         dej        defdZdefdZdS )r]   a/  
    The Box class boxes and unboxes messages between a pair of keys

    The ciphertexts generated by :class:`~nacl.public.Box` include a 16
    byte authenticator which is checked as part of the decryption. An invalid
    authenticator will cause the decrypt function to raise an exception. The
    authenticator is not a signature. Once you've decrypted the message you've
    demonstrated the ability to create arbitrary valid message, so messages you
    send are repudiable. For non-repudiable messages, sign them after
    encryption.

    :param private_key: :class:`~nacl.public.PrivateKey` used to encrypt and
        decrypt messages
    :param public_key: :class:`~nacl.public.PublicKey` used to encrypt and
        decrypt messages

    :cvar NONCE_SIZE: The size that the nonce is required to be.
    
NONCE_SIZE_shared_keyrE   r   c                 D   t          |t                    rt          |t                    st          j        d          t
          j                            |                    t          j
                  |                    t          j
                            | _        d S )Nz5Box must be created from a PrivateKey and a PublicKeyrW   )r   rC   r   r   r   r/   r0   crypto_box_beforenmencoder   r?   ra   )r   rE   r   s      r   r   zBox.__init__   s    +z22 	*	;
 ;
 	 -G    =<<h&9::x':;;
 
r    r!   c                     | j         S r#   ra   r%   s    r   r&   zBox.__bytes__   r'   r    rM   encodedr   c                 d    |                      |           }|                    |          |_        |S )z[
        Alternative constructor. Creates a Box from an existing Box's shared key.
        )__new__r   ra   )rM   rg   r   boxs       r   r   z
Box.decode   s/     KK$$ "..11
r    N	plaintextnoncec                    |t          | j                  }t          |          | j        k    rt          j        d| j        z            t
          j                            ||| j                  }|	                    |          }|	                    |          }t          j        |||	                    ||z                       S )a  
        Encrypts the plaintext message using the given `nonce` (or generates
        one randomly if omitted) and returns the ciphertext encoded with the
        encoder.

        .. warning:: It is **VITALLY** important that the nonce is a nonce,
            i.e. it is a number used only once for any given key. If you fail
            to do this, you compromise the privacy of the messages encrypted.

        :param plaintext: [:class:`bytes`] The plaintext message to encrypt
        :param nonce: [:class:`bytes`] The nonce to use in the encryption
        :param encoder: The encoder to use to encode the ciphertext
        :rtype: [:class:`nacl.utils.EncryptedMessage`]
        N'The nonce must be exactly %s bytes long)r   r`   r   r   r   r/   r0   crypto_box_afternmra   rd   r   _from_parts)r   rk   rl   r   
ciphertextencoded_nonceencoded_ciphertexts          r   encryptzBox.encrypt   s    ( =4?++Eu::((.9DOK   ]55
 

  u--$^^J77+NN5:-..
 
 	
r    rq   c                 $   |                     |          }||d| j                 }|| j        d         }t          |          | j        k    rt          j        d| j        z            t
          j                            ||| j                  }|S )a  
        Decrypts the ciphertext using the `nonce` (explicitly, when passed as a
        parameter or implicitly, when omitted, as part of the ciphertext) and
        returns the plaintext message.

        :param ciphertext: [:class:`bytes`] The encrypted message to decrypt
        :param nonce: [:class:`bytes`] The nonce used when encrypting the
            ciphertext
        :param encoder: The encoder used to decode the ciphertext.
        :rtype: [:class:`bytes`]
        Nrn   )	r   r`   r   r   r   r/   r0   crypto_box_open_afternmra   )r   rq   rl   r   rk   s        r   decryptzBox.decrypt  s    $ ^^J//
=001E#DO$5$56Ju::((.9DOK   M99
 
	 r    c                     | j         S )a  
        Returns the Curve25519 shared secret, that can then be used as a key in
        other symmetric ciphers.

        .. warning:: It is **VITALLY** important that you use a nonce with your
            symmetric cipher. If you fail to do this, you compromise the
            privacy of the messages encrypted. Ensure that the key length of
            your cipher is 32 bytes.
        :rtype: [:class:`bytes`]
        rf   r%   s    r   
shared_keyzBox.shared_key3  s     r    )r8   r9   r:   r;   r/   r0   crypto_box_NONCEBYTESr`   r   r=   r>   r   rC   r   r   r&   r[   r   r?   r   r\   r
   r   r   r   rt   rw   ry   r5   r    r   r]   r]      s         & !% CJCCC

J 

I 

 

 

 

 5         <D<O $Z"'29	   [" "&$,$7	)
 )
)
 )
 !	)

 
)
 )
 )
 )
\ "&$,$7	$ $$ $ !	$
 
$ $ $ $L E            r    _Keyc            	           e Zd ZU dZeed<   ee         ed<   defdZdefdZ	e
j        fded	e
j        defd
Ze
j        fddded	e
j        defdZdS )	SealedBoxa_  
    The SealedBox class boxes and unboxes messages addressed to
    a specified key-pair by using ephemeral sender's keypairs,
    whose private part will be discarded just after encrypting
    a single plaintext message.

    The ciphertexts generated by :class:`~nacl.public.SecretBox` include
    the public part of the ephemeral key before the :class:`~nacl.public.Box`
    ciphertext.

    :param recipient_key: a :class:`~nacl.public.PublicKey` used to encrypt
        messages and derive nonces, or a :class:`~nacl.public.PrivateKey` used
        to decrypt messages.

    .. versionadded:: 1.2
    r   rH   recipient_keyc                 |   t          |t                    r.|                    t          j                  | _        d | _        d S t          |t                    rQ|                    t          j                  | _        |j                            t          j                  | _        d S t          j
        d          )NrW   z:SealedBox must be created from a PublicKey or a PrivateKey)r   r   rd   r   r?   r   rH   rC   r   r   r   )r   r~   s     r   r   zSealedBox.__init__Z  s    mY// 	,33 +  4    D !%Dz22 
	 - 4 4 + !5 ! !D  -7>> +  ?    D -L  r    r!   c                     | j         S r#   r$   r%   s    r   r&   zSealedBox.__bytes__l  r'   r    rk   r   c                 z    t           j                            || j                  }|                    |          }|S )ay  
        Encrypts the plaintext message using a random-generated ephemeral
        keypair and returns a "composed ciphertext", containing both
        the public part of the keypair and the ciphertext proper,
        encoded with the encoder.

        The private part of the ephemeral key-pair will be scrubbed before
        returning the ciphertext, therefore, the sender will not be able to
        decrypt the generated ciphertext.

        :param plaintext: [:class:`bytes`] The plaintext message to encrypt
        :param encoder: The encoder to use to encode the ciphertext
        :return bytes: encoded ciphertext
        )r/   r0   crypto_box_sealr   rd   )r   rk   r   rq   rs   s        r   rt   zSealedBox.encrypto  s6    ( ]229d>NOO
$^^J77!!r    r   zSealedBox[PrivateKey]rq   c                     |                     |          }| j        t          d          t          j                            || j        | j                  }|S )a  
        Decrypts the ciphertext using the ephemeral public key enclosed
        in the ciphertext and the SealedBox private key, returning
        the plaintext message.

        :param ciphertext: [:class:`bytes`] The encrypted message to decrypt
        :param encoder: The encoder used to decode the ciphertext.
        :return bytes: The original plaintext
        :raises TypeError: if this SealedBox was created with a
            :class:`~nacl.public.PublicKey` rather than a
            :class:`~nacl.public.PrivateKey`.
        Nz4SealedBoxes created with a public key cannot decrypt)r   rH   r   r/   r0   crypto_box_seal_openr   )r   rq   r   rk   s       r   rw   zSealedBox.decrypt  sc    $ ^^J//
$F   M66
 
	 r    N)r8   r9   r:   r;   r   r>   r   r{   r   r&   r   r?   r
   rt   rw   r5   r    r   r}   r}   E  s          " 5/!!!d    $ 5         %-$7" "" !" 
	" " " ": %-$7 % ! 
	     r    r}   )typingr   r   r   r   r   nacl.bindingsr/   r   r	   r   nacl.encodingr
   
nacl.utilsr   r   r   	Encodabler   rC   r\   r]   r{   r}   r5   r    r   <module>r      s   > = = = = = = = = = = = = =           " " " " " " ! ! ! ! ! ! < < < < < < < < < <)# )# )# )# )#"K )# )# )#XdI dI dI dI dI#[ dI dI dIN wvU###R  R  R  R  R (
k R  R  R j wvy*--b b b b bx1; b b b b br    