a
    ł!f  ć                   @   sd   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 G dd deZG d	d
 d
eZdS )z2pyCrypto Crypto-related routines for oauth2client.é    )ŚSHA256)ŚRSA)Ś
PKCS1_v1_5)ŚDerSequence)Ś_helpersc                   @   s,   e Zd ZdZdd Zdd Zedd ZdS )	ŚPyCryptoVerifierz$Verifies the signature on a message.c                 C   s
   || _ dS )zConstructor.

        Args:
            pubkey: OpenSSL.crypto.PKey (or equiv), The public key to verify
            with.
        N)Ś_pubkey)ŚselfŚpubkey© r   ś]/var/www/html/python-backend/venv/lib/python3.9/site-packages/oauth2client/_pycrypto_crypt.pyŚ__init__   s    zPyCryptoVerifier.__init__c                 C   s(   t j|dd}t | j” t |”|”S )a£  Verifies a message against a signature.

        Args:
            message: string or bytes, The message to verify. If string, will be
                     encoded to bytes as utf-8.
            signature: string or bytes, The signature on the message.

        Returns:
            True if message was signed by the private key associated with the
            public key that this object was constructed with.
        śutf-8©Śencoding)r   Ś	_to_bytesr   Śnewr   Śverifyr   )r	   ŚmessageŚ	signaturer   r   r   r   $   s    
’zPyCryptoVerifier.verifyc                 C   s|   |rjt  | ”} |  dd” ” }t  d |dd ””}t }| |” t }| |d ” t 	|d ”}n
t 	| ”}t
|S )a@  Construct a Verified instance from a string.

        Args:
            key_pem: string, public key in PEM format.
            is_x509_cert: bool, True if key_pem is an X509 cert, otherwise it
                          is expected to be an RSA key in PEM format.

        Returns:
            Verifier instance.
        ó    ó    é   é’’’’r   é   )r   r   ŚreplaceŚsplitZ_urlsafe_b64decodeŚjoinr   Śdecoder   Ś	importKeyr   )Zkey_pemZis_x509_certZpemLinesZcertDerZcertSeqZtbsSeqr
   r   r   r   Śfrom_string4   s    


zPyCryptoVerifier.from_stringN)Ś__name__Ś
__module__Ś__qualname__Ś__doc__r   r   Śstaticmethodr    r   r   r   r   r      s
   	r   c                   @   s.   e Zd ZdZdd Zdd Zed
ddZd	S )ŚPyCryptoSignerz"Signs messages with a private key.c                 C   s
   || _ dS )ztConstructor.

        Args:
            pkey, OpenSSL.crypto.PKey (or equiv), The private key to sign with.
        N)Ś_key)r	   Śpkeyr   r   r   r   Q   s    zPyCryptoSigner.__init__c                 C   s&   t j|dd}t | j” t |””S )z±Signs a message.

        Args:
            message: string, Message to be signed.

        Returns:
            string, The signature of the message for the given key.
        r   r   )r   r   r   r   r'   Śsignr   )r	   r   r   r   r   r)   Y   s    	zPyCryptoSigner.signŚ
notasecretc                 C   s0   t  t  | ””}|r t |”}ntdt|S )a_  Construct a Signer instance from a string.

        Args:
            key: string, private key in PEM format.
            password: string, password for private key file. Unused for PEM
                      files.

        Returns:
            Signer instance.

        Raises:
            NotImplementedError if the key isn't in PEM format.
        zpNo key in PEM format was detected. This implementation can only use the PyCrypto library for keys in PEM format.)r   Z_parse_pem_keyr   r   r   ŚNotImplementedErrorr&   )ŚkeyŚpasswordZparsed_pem_keyr(   r   r   r   r    e   s    ’zPyCryptoSigner.from_stringN)r*   )r!   r"   r#   r$   r   r)   r%   r    r   r   r   r   r&   N   s
   r&   N)r$   ZCrypto.Hashr   ZCrypto.PublicKeyr   ZCrypto.Signaturer   ZCrypto.Util.asn1r   Zoauth2clientr   Śobjectr   r&   r   r   r   r   Ś<module>   s   6