
    Ri7              
          U d dl mZ d dlmZ d dlmZmZ d dlm	Z	 ddgZ
 ej                    Zeed<    ej                    Zeed<    ej                    Zeed	<    ej                    Zeed
<    ej                    Zeed<    ej                    Zeed<    ej                    Zeed<    ej                    Zeed<    ej                    Zeed<   deeef         fdZ dedeeef         fdZ!dededededef
dZ"dededededef
dZ#dededefdZ$dedededefdZ%dedededefdZ&dededededef
dZ'dededededef
d Z(dedededefd!Z)dedededefd"Z*dededefd#Z+dedededefd$Z,d%S )&    )Tuple)
exceptions)ffilib)ensurecrypto_box_keypair
crypto_boxcrypto_box_SECRETKEYBYTEScrypto_box_PUBLICKEYBYTEScrypto_box_SEEDBYTEScrypto_box_NONCEBYTEScrypto_box_ZEROBYTEScrypto_box_BOXZEROBYTEScrypto_box_BEFORENMBYTEScrypto_box_SEALBYTEScrypto_box_MACBYTESreturnc                  \   t          j        dt                    } t          j        dt                    }t	          j        | |          }t          |dk    dt          j                   t          j	        | t                    dd         t          j	        |t                    dd         fS )zq
    Returns a randomly generated public and secret key.

    :rtype: (bytes(public_key), bytes(secret_key))
    unsigned char[]r   Unexpected library errorraisingN)
r   newr   r
   r   r   r   excRuntimeErrorbuffer)pkskrcs      P/srv/django_bis/venv311/lib/python3.11/site-packages/nacl/bindings/crypto_box.pyr   r   #   s     
"$=	>	>B	"$=	>	>B		B	'	'B
27.8HIIII 	
2011!!!4
2011!!!4     seedc                 
   t          t          | t                    dt                     t	          |           t
          k    rt          j        d          t          j	        dt                    }t          j	        dt                    }t          j        |||           }t          |dk    dt          j                   t          j        |t                    dd         t          j        |t                    dd         fS )a  
    Returns a (public, secret) key pair deterministically generated
    from an input ``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: bytes
    :rtype: (bytes(public_key), bytes(secret_key))
    zseed must be bytesr   zInvalid seedr   r   r   N)r   
isinstancebytes	TypeErrorlenr   r   
ValueErrorr   r   r   r
   r   crypto_box_seed_keypairr   r   )r"   r   r   r   s       r    r)   r)   5   s    " :dE""$8)LLLL
4yy(((n^,,,	"$=	>	>B	"$=	>	>B		$RT	2	2B
27.8HIIII 	
2011!!!4
2011!!!4 r!   messagenoncer   r   c                 R   t          |          t          k    rt          j        d          t          |          t          k    rt          j        d          t          |          t
          k    rt          j        d          dt          z  | z   }t          j        dt          |                    }t          j
        ||t          |          |||          }t          |dk    dt          j                   t          j        |t          |                    t          d	         S )

    Encrypts and returns a message ``message`` using the secret key ``sk``,
    public key ``pk``, and the nonce ``nonce``.

    :param message: bytes
    :param nonce: bytes
    :param pk: bytes
    :param sk: bytes
    :rtype: bytes
    Invalid nonce sizeInvalid public keyInvalid secret key    r   r   r   r   N)r'   r   r   r(   r   r
   r   r   r   r   r	   r   r   r   r   )r*   r+   r   r   padded
ciphertextr   s          r    r	   r	   W   s     5zz***n1222
2ww+++n1222
2ww+++n1222,,7F*CKK88J	
FCKKB	G	GB
27.8HIIII:j#f++../F/G/GHHr!   r3   c                 R   t          |          t          k    rt          j        d          t          |          t          k    rt          j        d          t          |          t
          k    rt          j        d          dt          z  | z   }t          j        dt          |                    }t          j
        ||t          |          |||          }t          |dk    dt          j                   t          j        |t          |                    t          d	         S )
  
    Decrypts and returns an encrypted message ``ciphertext``, using the secret
    key ``sk``, public key ``pk``, and the nonce ``nonce``.

    :param ciphertext: bytes
    :param nonce: bytes
    :param pk: bytes
    :param sk: bytes
    :rtype: bytes
    r.   r/   r0   r1   r   r   /An error occurred trying to decrypt the messager   N)r'   r   r   r(   r   r
   r   r   r   r   crypto_box_openr   CryptoErrorr   r   )r3   r+   r   r   r2   	plaintextress          r    r7   r7   t   s    5zz***n1222
2ww+++n1222
2ww+++n1222//:=F)3v;;77I

iVeR
L
LC
q9    :iV--.B.C.CDDr!   c                    t          |           t          k    rt          j        d          t          |          t          k    rt          j        d          t          j        dt                    }t          j	        || |          }t          |dk    dt          j                   t          j        |t                    dd         S )a  
    Computes and returns the shared key for the public key ``pk`` and the
    secret key ``sk``. This can be used to speed up operations where the same
    set of keys is going to be used multiple times.

    :param pk: bytes
    :param sk: bytes
    :rtype: bytes
    r/   r0   r   r   r   r   N)r'   r   r   r(   r
   r   r   r   r   crypto_box_beforenmr   r   r   )r   r   kr   s       r    r<   r<      s     2ww+++n1222
2ww+++n1222!#;<<A		 B	+	+B
27.8HIIII:a12211155r!   r=   c                    t          |          t          k    rt          j        d          t          |          t          k    rt          j        d          dt
          z  | z   }t          j        dt          |                    }t          j	        ||t          |          ||          }t          |dk    dt          j                   t          j        |t          |                    t          d         S )	
    Encrypts and returns the message ``message`` using the shared key ``k`` and
    the nonce ``nonce``.

    :param message: bytes
    :param nonce: bytes
    :param k: bytes
    :rtype: bytes
    Invalid nonceInvalid shared keyr1   r   r   r   r   N)r'   r   r   r(   r   r   r   r   r   crypto_box_afternmr   r   r   r   )r*   r+   r=   r2   r3   r   s         r    rB   rB      s     5zz***n_---
1vv)))n1222++g5F*CKK88J		
FCKK	J	JB
27.8HIIII:j#f++../F/G/GHHr!   c                    t          |          t          k    rt          j        d          t          |          t          k    rt          j        d          dt
          z  | z   }t          j        dt          |                    }t          j	        ||t          |          ||          }t          |dk    dt          j                   t          j        |t          |                    t          d         S )	
    Decrypts and returns the encrypted message ``ciphertext``, using the shared
    key ``k`` and the nonce ``nonce``.

    :param ciphertext: bytes
    :param nonce: bytes
    :param k: bytes
    :rtype: bytes
    r@   rA   r1   r   r   r6   r   N)r'   r   r   r(   r   r   r   r   r   crypto_box_open_afternmr   r8   r   r   )r3   r+   r=   r2   r9   r:   s         r    rE   rE      s     5zz***n_---
1vv)))n1222//:=F)3v;;77I

%iVeQ
O
OC
q9    :iV--.B.C.CDDr!   c                    t          |          t          k    rt          j        d          t          |          t          k    rt          j        d          t          |          t
          k    rt          j        d          t          |           }t          |z   }t          j        d|          }t          j
        || ||||          }t          |dk    dt          j                   t          j        ||          dd         S )	r-   r.   r/   r0   r   r   r   r   N)r'   r   r   r(   r   r
   r   r   r   r   crypto_box_easyr   r   r   )r*   r+   r   r   _mlen_clenr3   r   s           r    rG   rG      s     5zz***n1222
2ww+++n1222
2ww+++n1222LLE%'E*E22J		Z%B	G	GB
27.8HIIII:j%((++r!   c                    t          |          t          k    rt          j        d          t          |          t          k    rt          j        d          t          |          t
          k    rt          j        d          t          |           }t          |t          k    d                    t                    t          j	                   |t          z
  }t          j        dt          d|                    }t          j        || ||||          }t          |dk    d	t          j                   t          j        ||          d
d
         S )r5   r.   r/   r0   )Input ciphertext must be at least {} longr   r      r   r6   N)r'   r   r   r(   r   r
   r   r   formatr&   r   r   maxr   crypto_box_open_easyr8   r   )r3   r+   r   r   rI   rH   r9   r:   s           r    rO   rO     s9    5zz***n1222
2ww+++n1222
2ww+++n1222
OOE
$$3::	
 	
     ''E)3q%==99I

"9j%B
O
OC
q9    :i''**r!   c                    t          |          t          k    rt          j        d          t          |          t          k    rt          j        d          t          |           }t
          |z   }t          j        d|          }t          j	        || |||          }t          |dk    dt          j                   t          j        ||          dd         S )r?   r@   rA   r   r   r   r   N)r'   r   r   r(   r   r   r   r   r   crypto_box_easy_afternmr   r   r   )r*   r+   r=   rH   rI   r3   r   s          r    rQ   rQ   6  s     5zz***n_---
1vv)))n1222LLE%'E*E22J		$Z%	J	JB
27.8HIIII:j%((++r!   c                 N   t          |          t          k    rt          j        d          t          |          t          k    rt          j        d          t          |           }t          |t          k    d                    t                    t          j                   |t          z
  }t          j
        dt          d|                    }t          j        || |||          }t          |dk    dt          j                   t          j        ||          d	d	         S )
rD   r@   rA   rK   r   r   rL   r   r6   N)r'   r   r   r(   r   r   r   rM   r&   r   r   rN   r   crypto_box_open_easy_afternmr8   r   )r3   r+   r=   rI   rH   r9   r:   s          r    rS   rS   Q  s    5zz***n_---
1vv)))n1222
OOE
$$3::	
 	
     ''E)3q%==99I

*:ueQ C q9    :i''**r!   c                    t          t          | t                    dt                     t          t          |t                    dt                     t	          |          t
          k    rt          j        d          t	          |           }t          |z   }t          j
        d|          }t          j        || ||          }t          |dk    dt          j                   t          j        ||          dd         S )	a  
    Encrypts and returns a message ``message`` using an ephemeral secret key
    and the public key ``pk``.
    The ephemeral public key, which is embedded in the sealed box, is also
    used, in combination with ``pk``, to derive the nonce needed for the
    underlying box construct.

    :param message: bytes
    :param pk: bytes
    :rtype: bytes

    .. versionadded:: 1.2
    zinput message must be bytesr   public key must be bytesr/   r   r   r   N)r   r$   r%   r&   r'   r   r   r(   r   r   r   r   crypto_box_sealr   r   )r*   r   rH   rI   r3   r   s         r    rV   rV   }  s     7E""%    2u99    2ww+++n1222LLE 5(E*E22J		Z%	<	<B
27.8HIIII:j%((++r!   c                 J   t          t          | t                    dt                     t          t          |t                    dt                     t          t          |t                    dt                     t	          |          t
          k    rt          j        d          t	          |          t          k    rt          j        d          t	          |           }t          |t          k    d
                    t                    t          j                   |t          z
  }t          j        dt          d	|                    }t          j        || |||          }t          |d
k    dt          j                   t          j        ||          dd         S )a  
    Decrypts and returns an encrypted message ``ciphertext``, using the
    recipent's secret key ``sk`` and the sender's ephemeral public key
    embedded in the sealed box. The box construct nonce is derived from
    the recipient's public key ``pk`` and the sender's public key.

    :param ciphertext: bytes
    :param pk: bytes
    :param sk: bytes
    :rtype: bytes

    .. versionadded:: 1.2
    zinput ciphertext must be bytesr   rU   zsecret key must be bytesr/   r0   rK   r   rL   r   r6   N)r   r$   r%   r&   r'   r   r   r(   r
   r   rM   r   r   rN   r   crypto_box_seal_openr8   r   )r3   r   r   rI   rH   r9   r:   s          r    rX   rX     s    :u%%(    2u99    2u99    2ww+++n1222
2ww+++n1222
OOE
%%	4<< 	
 	
     ((E )3q%==99I

"9j%R
H
HC
q9    :i''**r!   N)-typingr   naclr   r   nacl._sodiumr   r   nacl.exceptionsr   __all__crypto_box_secretkeybytesr
   int__annotations__crypto_box_publickeybytesr   crypto_box_seedbytesr   crypto_box_noncebytesr   crypto_box_zerobytesr   crypto_box_boxzerobytesr   crypto_box_beforenmbytesr   crypto_box_sealbytesr   crypto_box_macbytesr   r%   r   r)   r	   r7   r<   rB   rE   rG   rO   rQ   rS   rV   rX    r!   r    <module>rj      s          " " " " " " ! ! ! ! ! ! ! ! " " " " " "  
. "?!>!@!@ 3 @ @ @!>!>!@!@ 3 @ @ @4C466 c 6 6 66S688 s 8 8 84C466 c 6 6 6:s:<<  < < < < < > > # > > >4C466 c 6 6 623244 S 4 4 4E%,/    $% E%,,?    DI Ie I IE Ie I I I I: E E# E). E49 E
 E  E  E  EF6E 6u 6 6 6 6 60I Ie I I% I I I I2EE#E(-E
E E E E>,, ,&+,16,
, , , ,B++++#++).++49++
++ ++ ++ ++\,U ,5 ,U ,u , , , ,6)+)+#)+(-)+
)+ )+ )+ )+X#,U #, #,% #, #, #, #,L8+U 8+ 8+5 8+U 8+ 8+ 8+ 8+ 8+ 8+r!   