%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/nacl/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/nacl/__pycache__/public.cpython-312.pyc

�

�f�9��@�ddlmZmZmZmZmZddlZddlmZddlm	Z
ddlmZddl
mZmZmZGd�dej"e�ZGd	�d
ej"e�Zedd�
�ZGd�dej"e�Zedee�ZGd�deeej"e�Zy)�)�ClassVar�Generic�Optional�Type�TypeVarN)�encoding)�
exceptions)�Encoder)�EncryptedMessage�StringFixer�randomc���eZdZUdZej
jZee	e
d<ejfde
dejfd�Zde
fd�Zde	fd�Zd	edefd
�Zd	edefd�Zy)
�	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�.�|j|�|_t|jt�st	j
d��t
|j�|jk7r.t	jdj|j���y)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)�selfrrs   �-/usr/lib/python3/dist-packages/nacl/public.py�__init__zPublicKey.__init__$sw��
#�>�>�*�5����$�*�*�E�2��-�-� I�J�J��t��� �D�I�I�-��.�.�>�E�E��I�I���
�.��returnc��|jS�N�r�rs r�	__bytes__zPublicKey.__bytes__4������r c�*�tt|��Sr#)�hashrr%s r�__hash__zPublicKey.__hash__7s���E�$�K� � r �otherc��t||j�sytjj	t|�t|��S�NF)r�	__class__�nacl�bindings�
sodium_memcmpr�rr+s  r�__eq__zPublicKey.__eq__:s2���%����0���}�}�*�*�5��;��e��E�Er c��||k(Sr#�r2s  r�__ne__zPublicKey.__ne__?����E�M�"�"r N)�__name__�
__module__�__qualname__�__doc__r/r0�crypto_box_PUBLICKEYBYTESrr�int�__annotations__r�
RawEncoderrr
rr&r*�object�boolr3r6r5r rrrs�����-�-�A�A�D�(�3�-�A�
%-�$7�$7�����!�!��  �5� �!�#�!�F�F�F�t�F�
#�F�#�t�#r rc�Z�eZdZUdZej
jZee	e
d<ej
jZee	e
d<e
jfdede
j fd�Zee
jfdede
j ddfd	��Zdefd
�Zde	fd�Zdedefd
�Zdedefd�Zedd��Zy)�
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_keyrc�>�|j|�}t|t�rt|�|jk(s.tjdj|j���tjj|�}||_t|�|_
y)Nz>PrivateKey must be created from a {} bytes long raw secret key)rrrrrrrrr/r0�crypto_scalarmult_base�_private_keyrr)rrEr�raw_public_keys    rrzPrivateKey.__init__Ws|���n�n�[�1��
�{�E�*�s�;�/?�4�9�9�/L��-�-�0��&����#�	�
����=�=�k�J��'���#�N�3��r �seedr!c�$�|j|�}t|t�rt|�|jk(s.tjdj|j���tjj|�\}}||�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)rrrrrDrrrr/r0�crypto_box_seed_keypair)�clsrJr�raw_pk�raw_sks     r�	from_seedzPrivateKey.from_seednss��,�~�~�d�#���4��'�C��I����,F��-�-�&��&����'�	�
����>�>�t�D�����6�{�r c��|jSr#)rHr%s rr&zPrivateKey.__bytes__�s��� � � r c�T�tt|�t|j�f�Sr#)r)�typerrr%s rr*zPrivateKey.__hash__�s���T�$�Z��t���!7�8�9�9r r+c�b�t||j�sy|j|jk(Sr-)rr.rr2s  rr3zPrivateKey.__eq__�s(���%����0�����%�"2�"2�2�2r c��||k(Sr#r5r2s  rr6zPrivateKey.__ne__�r7r c�`�|ttj�tj��S)z~
        Generates a random :class:`~nacl.public.PrivateKey` object

        :rtype: :class:`~nacl.public.PrivateKey`
        �r)r
rCrrr?)rMs r�generatezPrivateKey.generate�s ���6�*�/�/�*�H�4G�4G�H�Hr N)r!rC)r8r9r:r;r/r0�crypto_box_SECRETKEYBYTESrrr=r>�crypto_box_SEEDBYTESrDrr?rr
r�classmethodrPr&r*r@rAr3r6rXr5r rrCrCCs���� �-�-�A�A�D�(�3�-�A�#�}�}�A�A�I�x��}�A�
%-�$7�$7�4��4��!�!�4�.�%-�$7�$7�!��!��!�!�!�
�	!��!�F!�5�!�:�#�:�3�F�3�t�3�
#�F�#�t�#��I��Ir rC�_Box�Box)�boundc
�X�eZdZUdZej
jZee	e
d<ee
d<dede
fd�Zdefd�Zeej$fd	eed
ededefd��Zd
ej$fdedeedej*defd�Zd
ej$fdedeedej*defd�Zdefd�Zy
)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_keyrErc�0�t|t�rt|t�stjd��t
jj|jtj��|jtj���|_y)Nz5Box must be created from a PrivateKey and a PublicKeyrW)rrCrrrr/r0�crypto_box_beforenm�encoderr?ra)rrErs   rrzBox.__init__�su���+�z�2�*��	�;
��-�-�G��
� �=�=�<�<����h�&9�&9��:����x�':�':��;�
��r r!c��|jSr#�rar%s rr&z
Box.__bytes__�r'r rM�encodedrc�T�|j|�}|j|�|_|S)z[
        Alternative constructor. Creates a Box from an existing Box's shared key.
        )�__new__rra)rMrgr�boxs    rrz
Box.decode�s)���K�K��$��"�.�.��1����
r N�	plaintext�noncec��|�t|j�}t|�|jk7r"tjd|jz��t
jj|||j�}|j|�}|j|�}tj|||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`]
        �'The nonce must be exactly %s bytes long)r
r`rrrr/r0�crypto_box_afternmrardr�_from_parts)rrkrlr�
ciphertext�
encoded_nonce�encoded_ciphertexts       r�encryptzBox.encrypt�s���(�=��4�?�?�+�E��u�:����(��.�.�9�D�O�O�K��
��]�]�5�5������
�
� ���u�-�
�$�^�^�J�7���+�+����N�N�5�:�-�.�
�	
r rqc�2�|j|�}|�|d|j}||jd}t|�|jk7r"tjd|jz��t
j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)	rr`rrrr/r0�crypto_box_open_afternmra)rrqrlrrks     r�decryptzBox.decrypt
s���$�^�^�J�/�
��=��0����1�E�#�D�O�O�$5�6�J��u�:����(��.�.�9�D�O�O�K��
��M�M�9�9������
�	��r c��|jS)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`]
        rfr%s r�
shared_keyzBox.shared_key3s�����r )r8r9r:r;r/r0�crypto_box_NONCEBYTESr`rr=r>rrCrrr&r[rr?rr\r
rrrrtrwryr5r rr]r]�s���&!%�
�
� C� C�J���
�C���

�J�

�I�

� �5� ��<D�<O�<O��
�$�Z��"'��29��	
����""&�$,�$7�$7�	)
��)
����)
��!�!�	)
�

�)
�\"&�$,�$7�$7�	$��$����$��!�!�	$�

�$�L �E� r �_Keyc	���eZdZUdZeed<eeed<defd�Zdefd�Z	e
jfded	e
jdefd
�Z
e
jfddd
ed	e
jdefd�Zy)�	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
    rrH�
recipient_keyc�p�t|t�r-|jtj��|_d|_yt|t�rU|jtj��|_|jjtj��|_ytjd��)NrWz:SealedBox must be created from a PublicKey or a PrivateKey)rrrdrr?rrHrCrrr)rr~s  rrzSealedBox.__init__Zs����m�Y�/�,�3�3� �+�+� 4� �D��!%�D��
�
�z�
2� -� 4� 4� �+�+�!5�!�D�� -�7�7�>�>� �+�+� ?� �D���-�-�L��
r r!c��|jSr#r$r%s rr&zSealedBox.__bytes__lr'r rkrc�|�tjj||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_sealrrd)rrkrrqrss     rrtzSealedBox.encryptos5��(�]�]�2�2�9�d�>N�>N�O�
�$�^�^�J�7��!�!r rzSealedBox[PrivateKey]rqc��|j|�}|j�td��tjj||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`.
        z4SealedBoxes created with a public key cannot decrypt)rrHrr/r0�crypto_box_seal_openr)rrqrrks    rrwzSealedBox.decrypt�sa��$�^�^�J�/�
����$��F��
��M�M�6�6��������
�	��r N)r8r9r:r;rr>rr{rr&rr?r
rtrwr5r rr}r}Es����"���5�/�!��d��$ �5� �%-�$7�$7�"��"��!�!�"�
�	"�:%-�$7�$7��%�����!�!��
�	r r})�typingrrrrr�
nacl.bindingsr/rr	r�
nacl.encodingr
�
nacl.utilsrrr
�	EncodablerrCr\r]r{r}r5r r�<module>r�s���>�=���"�!�<�<�)#��"�"�K�)#�XdI��#�#�[�dI�N�v�U�#��R �(�
�
�k�R �j�v�y�*�-��b���
�x�1�1�;�br 

Zerion Mini Shell 1.0