
    Ii9                     :   S SK JrJrJrJrJr  S SKrS SKJr  S SKJ	r
  S SKJr  S SKJrJrJr   " S S\R"                  \5      r " S	 S
\R"                  \5      r\" SSS9r " S S\R"                  \5      r\" S\\5      r " S S\\   \R"                  \5      rg)    )ClassVarGenericOptionalTypeTypeVarN)encoding)
exceptions)Encoder)EncryptedMessageStringFixerrandomc                       \ rS rSr% Sr\R                  R                  r\	\
   \S'   \R                  4S\S\R                  4S jjrS\4S jrS\
4S	 jrS
\S\4S jrS
\S\4S jrSrg)	PublicKey   a%  
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                 >   UR                  U5      U l        [        U R                  [        5      (       d  [        R
                  " S5      e[        U R                  5      U R                  :w  a/  [        R                  " SR                  U R                  5      5      eg )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      1/venv/lib/python3.13/site-packages/nacl/public.py__init__PublicKey.__init__$   sz    
 #>>*5$**E22-- IJJt DII-..>EEII  .    returnc                     U R                   $ Nr   r   s    r   	__bytes__PublicKey.__bytes__4       r"   c                 *    [        [        U 5      5      $ r%   )hashr   r'   s    r   __hash__PublicKey.__hash__7   s    E$K  r"   otherc                     [        XR                  5      (       d  g[        R                  R	                  [        U 5      [        U5      5      $ NF)r   	__class__naclbindingssodium_memcmpr   r   r/   s     r   __eq__PublicKey.__eq__:   s3    %00}}**5;eEEr"   c                     X:X  + $ r%    r6   s     r   __ne__PublicKey.__ne__?       ""r"   r&   N)__name__
__module____qualname____firstlineno____doc__r3   r4   crypto_box_PUBLICKEYBYTESr   r   int__annotations__r   
RawEncoderr   r
   r    r(   r-   objectboolr7   r;   __static_attributes__r:   r"   r   r   r      s     --AAD(3-A
 %-$7$7 !!  5  !# !FF Ft F
#F #t #r"   r   c                   t   \ rS rSr% Sr\R                  R                  r\	\
   \S'   \R                  R                  r\	\
   \S'   \R                  4S\S\R"                  4S jjr\\R                  4S\S\R"                  S	S 4S
 jj5       rS	\4S jrS	\
4S jrS\S	\4S jrS\S	\4S jr\SS j5       rSrg)
PrivateKeyC   aO  
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                 J   UR                  U5      n[        U[        5      (       a  [        U5      U R                  :X  d/  [
        R                  " SR                  U R                  5      5      e[        R                  R                  U5      nXl        [        U5      U l        g )Nz>PrivateKey must be created from a {} bytes long raw secret key)r   r   r   r   r   r   r   r   r3   r4   crypto_scalarmult_base_private_keyr   r   )r   rN   r   raw_public_keys       r   r    PrivateKey.__init__W   s}     nn[1 {E**s;/?499/L--0&#	  ==kJ'#N3r"   seedr#   c                 0   UR                  U5      n[        U[        5      (       a  [        U5      U R                  :X  d/  [
        R                  " SR                  U R                  5      5      e[        R                  R                  U5      u  p4U " U5      $ )a  
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   rM   r   r   r   r3   r4   crypto_box_seed_keypair)clsrT   r   raw_pkraw_sks        r   	from_seedPrivateKey.from_seedn   st    , ~~d#4''CI,F--&&'	  >>tD6{r"   c                     U R                   $ r%   )rQ   r'   s    r   r(   PrivateKey.__bytes__   s       r"   c                 T    [        [        U 5      [        U R                  5      45      $ r%   )r,   typer   r   r'   s    r   r-   PrivateKey.__hash__   s    T$Zt!7899r"   r/   c                 j    [        XR                  5      (       d  gU R                  UR                  :H  $ r1   )r   r2   r   r6   s     r   r7   PrivateKey.__eq__   s)    %00%"2"222r"   c                     X:X  + $ r%   r:   r6   s     r   r;   PrivateKey.__ne__   r=   r"   c                 Z    U " [        [        R                  5      [        R                  S9$ )zf
Generates a random :class:`~nacl.public.PrivateKey` object

:rtype: :class:`~nacl.public.PrivateKey`
r   )r   rK   r   r   rF   )rW   s    r   generatePrivateKey.generate   s      6*//*H4G4GHHr"   )rQ   r   N)r#   rK   )r>   r?   r@   rA   rB   r3   r4   crypto_box_SECRETKEYBYTESr   r   rD   rE   crypto_box_SEEDBYTESrM   r   rF   r   r
   r    classmethodrZ   r(   r-   rG   rH   r7   r;   rg   rI   r:   r"   r   rK   rK   C   s      --AAD(3-A#}}AAIx}A
 %-$7$744 !!4.  %-$7$7!! !!! 
	! !F!5 !:# :3F 3t 3
#F #t # I Ir"   rK   _BoxBox)boundc            
       r   \ rS rSr% Sr\R                  R                  r\	\
   \S'   \\S'   S\S\4S jrS\4S	 jr\\R&                  4S
\\   S\S\S\4S jj5       rS\R&                  4S\S\\   S\R,                  S\4S jjrS\R&                  4S\S\\   S\R,                  S\4S jjrS\4S jrSrg)rm      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_keyrN   r   c                 :   [        U[        5      (       a  [        U[        5      (       d  [        R                  " S5      e[
        R                  R                  UR                  [        R                  S9UR                  [        R                  S95      U l        g )Nz5Box must be created from a PrivateKey and a PublicKeyrf   )r   rK   r   r   r   r3   r4   crypto_box_beforenmencoder   rF   rr   )r   rN   r   s      r   r    Box.__init__   s}    +z22*	;
 ;
 --G   ==<<h&9&9:x':':;
r"   r#   c                     U R                   $ r%   rr   r'   s    r   r(   Box.__bytes__   r*   r"   rW   encodedr   c                 T    U R                  U 5      nUR                  U5      Ul        U$ )zK
Alternative constructor. Creates a Box from an existing Box's shared key.
)__new__r   rr   )rW   rz   r   boxs       r   r   
Box.decode   s)     KK$ "..1
r"   N	plaintextnoncec                    Uc  [        U R                  5      n[        U5      U R                  :w  a#  [        R                  " SU R                  -  5      e[
        R                  R                  UUU R                  5      nUR                  U5      nUR                  U5      n[        R                  " UUUR                  X$-   5      5      $ )aW  
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`]
'The nonce must be exactly %s bytes long)r   rq   r   r   r   r3   r4   crypto_box_afternmrr   ru   r   _from_parts)r   r   r   r   
ciphertextencoded_nonceencoded_ciphertexts          r   encryptBox.encrypt   s    ( =4??+Eu:(..9DOOK  ]]55

  u-$^^J7++NN5-.
 	
r"   r   c                 6   UR                  U5      nUc  USU R                   nXR                  S n[        U5      U R                  :w  a#  [        R                  " SU R                  -  5      e[
        R                  R                  UUU R                  5      nU$ )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`]
Nr   )	r   rq   r   r   r   r3   r4   crypto_box_open_afternmrr   )r   r   r   r   r   s        r   decryptBox.decrypt  s    $ ^^J/
=01E#OO$56Ju:(..9DOOK  MM99
	 r"   c                     U R                   $ )ag  
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`]
rx   r'   s    r   
shared_keyBox.shared_key3  s     r"   rx   )r>   r?   r@   rA   rB   r3   r4   crypto_box_NONCEBYTESrq   r   rD   rE   r   rK   r   r    r(   rk   r   rF   r   rl   r
   r   r   r   r   r   r   rI   r:   r"   r   rm   rm      s   & !% C CJC

J 

I 

 5   <D<O<O$Z"'29	 " "&$,$7$7	)
)
 )
 !!	)

 
)
\ "&$,$7$7	$$ $ !!	$
 
$L E  r"   _Keyc            	           \ rS rSr% Sr\\S'   \\   \S'   S\4S jr	S\4S jr
\R                  4S	\S
\R                  S\4S jjr\R                  4SSS\S
\R                  S\4S jjrSrg)	SealedBoxiE  a/  
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   rQ   recipient_keyc                 t   [        U[        5      (       a*  UR                  [        R                  S9U l        S U l        g [        U[        5      (       aO  UR                  [        R                  S9U l        UR                  R                  [        R                  S9U l        g [        R                  " S5      e)Nrf   z:SealedBox must be created from a PublicKey or a PrivateKey)r   r   ru   r   rF   r   rQ   rK   r   r   r   )r   r   s     r   r    SealedBox.__init__Z  s    mY//,33 ++  4  D !%Dz22 - 4 4 ++ !5 !D  -77>> ++  ?  D --L r"   r#   c                     U R                   $ r%   r&   r'   s    r   r(   SealedBox.__bytes__l  r*   r"   r   r   c                 z    [         R                  R                  XR                  5      nUR	                  U5      nU$ )a!  
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
)r3   r4   crypto_box_sealr   ru   )r   r   r   r   r   s        r   r   SealedBox.encrypto  s3    ( ]]229>N>NO
$^^J7!!r"   r   zSealedBox[PrivateKey]r   c                     UR                  U5      nU R                  c  [        S5      e[        R                  R                  UU R                  U R                  5      nU$ )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`.
z4SealedBoxes created with a public key cannot decrypt)r   rQ   r   r3   r4   crypto_box_seal_openr   )r   r   r   r   s       r   r   SealedBox.decrypt  sa    $ ^^J/
$F  MM66
	 r"   )rQ   r   N)r>   r?   r@   rA   rB   r   rE   r   r   r    r(   r   rF   r
   r   r   rI   r:   r"   r   r   r   E  s    " 5/!d $ 5   %-$7$7"" !!" 
	": %-$7$7% !! 
	 r"   r   )typingr   r   r   r   r   nacl.bindingsr3   r   r	   r   nacl.encodingr
   
nacl.utilsr   r   r   	Encodabler   rK   rl   rm   r   r   r:   r"   r   <module>r      s    > =   " ! < <)#""K )#XdI##[ dIN vU#R (

k R j vy*-bx11; br"   