§
    &xÅjM;  ã                   ó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      ú<C:\Projects\Historical\venv\Lib\site-packages\nacl/public.pyÚ__init__zPublicKey.__init__$   s‹   € ð
 #Ÿ>š>¨*Ñ5Ô5ˆÔÝ˜$Ô*­EÑ2Ô2ð 	KÝ”-Ð IÑJÔJÐJåˆtÔÑ Ô  D¤IÒ-Ð-Ý”.Ø>×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˜$‘K”KÑ Ô Ð 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__?   ó   € Ø˜E’MÐ"Ð"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ñ   € € € € € € ðð ð œ-ÔA€Dˆ(�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–   € ð —n’n [Ñ1Ô1ˆõ �{¥EÑ*Ô*ð	Ý/2°;Ñ/?Ô/?À4Ä9Ò/LÐ/Lå”-àTß’&˜œÑ#Ô#ñô ð õ œ×=Ò=¸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_seedm   sˆ   € ð, �~Š~˜dÑ#Ô#ˆå˜4¥Ñ'Ô'ð 	­C°©I¬I¸¼Ò,FÐ,FÝ”-àMß’&˜œÑ'Ô'ñô ð õ œ×>Ò>¸tÑDÔD‰ˆ�àˆs�6‰{Œ{Ð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˜$‘Z”Z¥ 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&   € ð ˆs•6�*œ/Ñ*Ô*µHÔ4GÐ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  € € € € € € ðð ð  œ-ÔA€Dˆ(�3Œ-ÐAÐAÑAØ#œ}ÔA€Iˆx˜Œ}ÐAÐAÑAð
 %-Ô$7ð4ð 4àð4ð Ô!ð4ð 4ð 4ð 4ð, ð %-Ô$7ð ð  àð ð Ô!ð ð 
ð	 ð  ð  ñ „[ð ðD!˜5ð !ð !ð !ð !ð:˜#ð :ð :ð :ð :ð3˜Fð 3 tð 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/   € ð —K’K Ñ$Ô$ˆð "Ÿ.š.¨Ñ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_easy_afternmra   rd   r   Ú_from_parts)r   rk   rl   r   Ú
ciphertextÚencoded_nonceÚencoded_ciphertexts          r   ÚencryptzBox.encryptà   sÂ   € ð( ˆ=Ý˜4œ?Ñ+Ô+ˆEåˆu‰:Œ:˜œÒ(Ð(Ý”.Ø9¸D¼OÑKñô ð õ ”]×:Ò:ØØØÔñ
ô 
ˆ
ð  Ÿš uÑ-Ô-ˆØ$Ÿ^š^¨JÑ7Ô7ÐåÔ+ØØØ�NŠN˜5 :Ñ-Ñ.Ô.ñ
ô 
ð 	
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_easy_afternmra   )r   rq   rl   r   rk   s        r   ÚdecryptzBox.decrypt  sœ   € ð$ —^’^ JÑ/Ô/ˆ
àˆ=àÐ0 ¤Ð0Ô1ˆEØ# D¤OÐ$5Ð$5Ô6ˆJåˆu‰:Œ:˜œÒ(Ð(Ý”.Ø9¸D¼OÑKñô ð õ ”M×>Ò>ØØØÔñ
ô 
ˆ	ð Ð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_key1  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’  € € € € € € ðð ð& !%¤Ô C€J�˜”Ð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 key pairs,
    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__X  sÃ   € Ý�m¥YÑ/Ô/ð 	Ø,×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__j  r'   r    rk   r   c                 óz   — t           j                             || j        ¦  «        }|                     |¦  «        }|S )a{  
        Encrypts the plaintext message using a random-generated ephemeral
        key pair and returns a "composed ciphertext", containing both
        the public part of the key pair 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.encryptm  s6   € õ( ”]×2Ò2°9¸dÔ>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}   C  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bIð bIð bIð bIð bI�Ô# [ñ bIô bIð bIðJ €wˆv˜UÐ#Ñ#Ô#€ðR ð R ð R ð R ð R ˆ(Ô
˜kñ R ô R ð R ðj €wˆv�y *Ñ-Ô-€ðbð bð bð bð b�˜”˜xÔ1°;ñ bô bð bð bð br    