Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/site-packages/nacl/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/site-packages/nacl/__pycache__/public.cpython-38.pyc
U

O��g�9�@s�ddlmZmZmZmZmZddlZddlmZddlm	Z
ddlmZddl
mZmZmZGdd�deje�ZGd	d
�d
eje�Zeddd
�ZGdd�deje�Zedee�ZGdd�deeeje�ZdS)�)�ClassVar�Generic�Optional�Type�TypeVarN)�encoding)�
exceptions)�Encoder)�EncryptedMessage�StringFixer�randomc@szeZdZUdZejjZee	e
d<ejfe
ejd�dd�Ze
d�dd�Ze	d�d	d
�Zeed�dd
�Zeed�dd�ZdS)�	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�encodercCsH|�|�|_t|jt�s"t�d��t|j�|jkrDt�d�	|j���dS)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)�selfrr�r�8/opt/cppython/lib/python3.8/site-packages/nacl/public.py�__init__$s
��zPublicKey.__init__��returncCs|jS�N�r�rrrr�	__bytes__4szPublicKey.__bytes__cCstt|��Sr )�hashrr"rrr�__hash__7szPublicKey.__hash__��otherrcCs&t||j�sdStj�t|�t|��S�NF)r�	__class__�nacl�bindingsZ
sodium_memcmpr�rr'rrr�__eq__:szPublicKey.__eq__cCs
||kSr rr,rrr�__ne__?szPublicKey.__ne__N)�__name__�
__module__�__qualname__�__doc__r*r+Zcrypto_box_PUBLICKEYBYTESrr�int�__annotations__r�
RawEncoderrr	rr#r%�object�boolr-r.rrrrr
s

��r
c@s�eZdZUdZejjZee	e
d<ejjZee	e
d<e
jfee
jd�dd�Zee
jfee
jdd�dd	��Zed
�dd�Ze	d
�d
d�Zeed�dd�Zeed�dd�Zedd
�dd��ZdS)�
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_keyrcCsT|�|�}t|t�r"t|�|jks4t�d�|j���tj	�
|�}||_t|�|_
dS)Nz>PrivateKey must be created from a {} bytes long raw secret key)rrrrrrrrr*r+Zcrypto_scalarmult_base�_private_keyr
r)rr:rZraw_public_keyrrrrWs
�����zPrivateKey.__init__)�seedrrcCsL|�|�}t|t�r"t|�|jks4t�d�|j���tj	�
|�\}}||�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)rrrrr9rrrr*r+Zcrypto_box_seed_keypair)�clsr<rZraw_pkZraw_skrrr�	from_seedns
���zPrivateKey.from_seedrcCs|jSr )r;r"rrrr#�szPrivateKey.__bytes__cCstt|�t|j�f�Sr )r$�typerrr"rrrr%�szPrivateKey.__hash__r&cCst||j�sdS|j|jkSr()rr)rr,rrrr-�szPrivateKey.__eq__cCs
||kSr rr,rrrr.�szPrivateKey.__ne__cCs|ttj�tjd�S)z~
        Generates a random :class:`~nacl.public.PrivateKey` object

        :rtype: :class:`~nacl.public.PrivateKey`
        �r)rr8rrr5)r=rrr�generate�szPrivateKey.generateN)r/r0r1r2r*r+Zcrypto_box_SECRETKEYBYTESrrr3r4Zcrypto_box_SEEDBYTESr9rr5rr	r�classmethodr>r#r%r6r7r-r.rArrrrr8Cs*
����#r8�_Box�Box)�boundc@s�eZdZUdZejjZee	e
d<ee
d<ee
d�dd�Zed�dd	�Zeejfeeeeed
�dd��Zd
ejfeeeejed�dd�Zd
ejfeeeejed�dd�Zed�dd�Zd
S)rDa/
    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_key)r:rcCsFt|t�rt|t�st�d��tj�|jt	j
d�|jt	j
d��|_dS)Nz5Box must be created from a PrivateKey and a PublicKeyr@)rr8r
rrr*r+Zcrypto_box_beforenm�encoderr5rG)rr:rrrrr�s���zBox.__init__rcCs|jSr �rGr"rrrr#�sz
Box.__bytes__)r=�encodedrrcCs|�|�}|�|�|_|S)z[
        Alternative constructor. Creates a Box from an existing Box's shared key.
        )�__new__rrG)r=rJr�boxrrrr�s
z
Box.decodeN)�	plaintext�noncerrcCsn|dkrt|j�}t|�|jkr0t�d|j��tj�|||j�}|�	|�}|�	|�}t
�|||�	||��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rFrrrr*r+Zcrypto_box_afternmrGrHr
�_from_parts)rrMrNr�
ciphertextZ
encoded_nonce�encoded_ciphertextrrr�encrypt�s$
��

�zBox.encrypt)rQrNrrcCsb|�|�}|dkr.|d|j�}||jd�}t|�|jkrLt�d|j��tj�|||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`]
        NrO)	rrFrrrr*r+Zcrypto_box_open_afternmrG)rrQrNrrMrrr�decrypt
s
��zBox.decryptcCs|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`]
        rIr"rrr�
shared_key3szBox.shared_key)r/r0r1r2r*r+Zcrypto_box_NONCEBYTESrFrr3r4rr8r
rr#rBrr5rrCr	rrr
rSrTrUrrrrrD�s<
����.��&�_Keyc@sxeZdZUdZeed<eeed<ed�dd�Zed�dd	�Z	e
jfee
jed
�dd�Z
e
jfd
ee
jed�dd�ZdS)�	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
    rr;)�
recipient_keycCs^t|t�r"|jtjd�|_d|_n8t|t�rP|jtjd�|_|jjtjd�|_n
t	�
d��dS)Nr@z:SealedBox must be created from a PublicKey or a PrivateKey)rr
rHrr5rr;r8rrr)rrXrrrrZs
�
��
�zSealedBox.__init__rcCs|jSr r!r"rrrr#lszSealedBox.__bytes__)rMrrcCstj�||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*r+Zcrypto_box_sealrrH)rrMrrQrRrrrrSos
zSealedBox.encryptzSealedBox[PrivateKey])rrQrrcCs4|�|�}|jdkrtd��tj�||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)rr;rr*r+Zcrypto_box_seal_openr)rrQrrMrrrrT�s

��zSealedBox.decryptN)r/r0r1r2rr4rrVrr#rr5r	rSrTrrrrrWEs$
����rW)�typingrrrrrZ
nacl.bindingsr*rrrZ
nacl.encodingr	Z
nacl.utilsr
rrZ	Encodabler
r8rCrDrVrWrrrr�<module>s,g

F1le Man4ger