
    h                     `    d Z ddlmZ ddlmZ  G d de          Z G d de          Zd Zd	S )
z1OpenSSL Crypto-related routines for oauth2client.    )crypto)_helpersc                   4    e Zd ZdZd Zd Zed             ZdS )OpenSSLVerifierz$Verifies the signature on a message.c                     || _         dS )zlConstructor.

        Args:
            pubkey: OpenSSL.crypto.PKey, The public key to verify with.
        N)_pubkey)selfpubkeys     s/home/visionen/pythonvenv/lib/python3.11/site-packages/oauth2client-4.1.3-py3.11.egg/oauth2client/_openssl_crypt.py__init__zOpenSSLVerifier.__init__   s         c                     t          j        |d          }t          j        |d          }	 t          j        | j        ||d           dS # t          j        $ r Y dS w xY w)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. If string,
                   will be encoded to bytes as utf-8.

        Returns:
            True if message was signed by the private key associated with the
            public key that this object was constructed with.
        utf-8encodingsha256TF)r   	_to_bytesr   verifyr   Error)r	   message	signatures      r   r   zOpenSSLVerifier.verify    st     $Ww???&y7CCC		M$,	7HEEE4| 	 	 	55	s   A AAc                     t          j        |           } |r t          j        t          j        |           }nt          j        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.

        Raises:
            OpenSSL.crypto.Error: if the key_pem can't be parsed.
        )r   r   r   load_certificateFILETYPE_PEMload_privatekeyr   )key_pemis_x509_certr
   s      r   from_stringzOpenSSLVerifier.from_string5   sW     $W-- 	J,V-@'JJFF+F,?IIFv&&&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 )OpenSSLSignerz"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OpenSSLSigner.__init__O   s     			r   c                 d    t          j        |d          }t          j        | j        |d          S )zSigns a message.

        Args:
            message: bytes, Message to be signed.

        Returns:
            string, The signature of the message for the given key.
        r   r   r   )r   r   r   signr(   )r	   r   s     r   r+   zOpenSSLSigner.signW   s/     $Ww???{49gx888r   
   notasecretc                 .   t          j        |           } t          j        |           }|r t          j        t          j        |          }n=t          j        |d          }t          j        | |                                          }t          |          S )a>  Construct a Signer instance from a string.

        Args:
            key: string, private key in PKCS12 or PEM format.
            password: string, password for the private key file.

        Returns:
            Signer instance.

        Raises:
            OpenSSL.crypto.Error if the key can't be parsed.
        r   r   )	r   r   _parse_pem_keyr   r   r   load_pkcs12get_privatekeyr&   )keypasswordparsed_pem_keyr)   s       r   r   zOpenSSLSigner.from_stringc   s      %%!055 	F)&*=~NNDD)(WEEEH%c844CCEEDT"""r   N)r,   )r   r    r!   r"   r   r+   r#   r   r$   r   r   r&   r&   L   sX        ,,  
9 
9 
9 # # # \# # #r   r&   c                     t          j        |          }t          j        | |          }t          j        t          j        |                                          S )a  Convert the contents of a PKCS#12 key to PEM using pyOpenSSL.

    Args:
        private_key_bytes: Bytes. PKCS#12 key in DER format.
        private_key_password: String. Password for PKCS#12 key.

    Returns:
        String. PEM contents of ``private_key_bytes``.
    )r   r   r   r/   dump_privatekeyr   r0   )private_key_bytesprivate_key_passwordpkcs12s      r   pkcs12_key_as_pemr9   {   sS     $-.BCC 13GHHF!&"5"("7"7"9"9; ; ;r   N)	r"   OpenSSLr   oauth2clientr   objectr   r&   r9   r$   r   r   <module>r=      s    8 7       ! ! ! ! ! !4' 4' 4' 4' 4'f 4' 4' 4'n,# ,# ,# ,# ,#F ,# ,# ,#^; ; ; ; ;r   