
    h                     ~    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e          Z G d	 d
e          ZdS )z2pyCrypto Crypto-related routines for oauth2client.    )SHA256)RSA)
PKCS1_v1_5)DerSequence)_helpersc                   4    e Zd ZdZd Zd Zed             ZdS )PyCryptoVerifierz$Verifies the signature on a message.c                     || _         dS )zConstructor.

        Args:
            pubkey: OpenSSL.crypto.PKey (or equiv), The public key to verify
            with.
        N)_pubkey)selfpubkeys     t/home/visionen/pythonvenv/lib/python3.11/site-packages/oauth2client-4.1.3-py3.11.egg/oauth2client/_pycrypto_crypt.py__init__zPyCryptoVerifier.__init__   s         c                     t          j        |d          }t          j        | j                                      t          j        |          |          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	signatures      r   r   zPyCryptoVerifier.verify$   sL     $Ww???~dl++22Jw, , 	,r   c                    |rt          j        |           } |                     dd                                          }t          j        d                    |dd                             }t                      }|                    |           t                      }|                    |d                    t          j	        |d                   }nt          j	        |           }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   r   replacesplit_urlsafe_b64decodejoinr   decoder   	importKeyr	   )key_pemis_x509_certpemLinescertDercertSeqtbsSeqr   s          r   from_stringzPyCryptoVerifier.from_string4   s      
	,(11GtS117799H1#((8AbD>2J2JKKG!mmGNN7### ]]FMM'!*%%%]6!9--FF]7++F'''r   N)__name__
__module____qualname____doc__r   r   staticmethodr+    r   r   r	   r	      sS        ..  , , ,  ( ( \( ( (r   r	   c                   6    e Zd ZdZd Zd Zedd            ZdS )PyCryptoSignerz"Signs messages with a private key.c                     || _         dS )ztConstructor.

        Args:
            pkey, OpenSSL.crypto.PKey (or equiv), The private key to sign with.
        N)_key)r   pkeys     r   r   zPyCryptoSigner.__init__Q   s     			r   c                     t          j        |d          }t          j        | j                                      t          j        |                    S )zSigns 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   r5   signr   )r   r   s     r   r8   zPyCryptoSigner.signY   sC     $Ww???~di((--fj.A.ABBBr   
notasecretc                     t          j        t          j        |                     }|rt          j        |          }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   _parse_pem_keyr   r   r$   NotImplementedErrorr3   )keypasswordparsed_pem_keyr6   s       r   r+   zPyCryptoSigner.from_stringe   s_     "01CC1H1HII 	=00DD%   d###r   N)r9   )r,   r-   r.   r/   r   r8   r0   r+   r1   r   r   r3   r3   N   s[        ,,  
C 
C 
C $ $ $ \$ $ $r   r3   N)r/   Crypto.Hashr   Crypto.PublicKeyr   Crypto.Signaturer   Crypto.Util.asn1r   oauth2clientr   objectr	   r3   r1   r   r   <module>rF      s    9 8                   ' ' ' ' ' ' ( ( ( ( ( ( ! ! ! ! ! !3( 3( 3( 3( 3(v 3( 3( 3(l.$ .$ .$ .$ .$V .$ .$ .$ .$ .$r   