U
    /2i                     @   s|   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 ddlm	Z	 dZ
G d	d
 d
e	jZG dd de	je	jZdS )z
RSA cryptography signer and verifier.

This file provides a shared wrapper, that defers to _python_rsa or _cryptography_rsa
for implmentations using different third party libraries
    )RSAPrivateKey)RSAPublicKey)_helpers)_cryptography_rsa)_python_rsa)basezrsa.keyc                   @   s8   e Zd ZdZdd Zeejdd Z	e
dd ZdS )	RSAVerifiera5  Verifies RSA cryptographic signatures using public keys.

    Args:
        public_key (Union["rsa.key.PublicKey", cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey]):
            The public key used to verify signatures.
    Raises:
        ValueError: if an unrecognized public key is provided
    c                 C   sJ   |j j}t|trt}n"|tr(t}ntdt	| |
|| _d S )Nzunrecognized public key type: )	__class__
__module__
isinstancer   r   
startswithRSA_KEY_MODULE_PREFIXr   
ValueErrortyper   _impl)self
public_key
module_strimpl_lib r   9/tmp/pip-unpacked-wheel-t7lbbs2b/google/auth/crypt/rsa.py__init__+   s    

zRSAVerifier.__init__c                 C   s   | j ||S N)r   verify)r   message	signaturer   r   r   r   5   s    zRSAVerifier.verifyc                 C   s   |  | }tj||_|S )a  Construct a Verifier instance from a public key or public
        certificate string.

        Args:
            public_key (Union[str, bytes]): The public key in PEM format or the
                x509 public key certificate.

        Returns:
            google.auth.crypt.Verifier: The constructed verifier.

        Raises:
            ValueError: If the public_key can't be parsed.
        )__new__r   r   from_stringr   )clsr   instancer   r   r   r   9   s    
zRSAVerifier.from_stringN)__name__r
   __qualname____doc__r   r   copy_docstringr   Verifierr   classmethodr   r   r   r   r   r   !   s   	


r   c                   @   sT   e Zd ZdZdddZeeej	dd Z
eej	dd Zedd	d
ZdS )	RSASignera  Signs messages with an RSA private key.

    Args:
        private_key (Union["rsa.key.PrivateKey", cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey]):
            The private key to sign with.
        key_id (str): Optional key ID used to identify this private key. This
            can be useful to associate the private key with its associated
            public key or certificate.

    Raises:
        ValueError: if an unrecognized public key is provided
    Nc                 C   sN   |j j}t|trt}n"|tr(t}ntdt	| |j
||d| _d S )Nzunrecognized private key type: key_id)r	   r
   r   r   r   r   r   r   r   r   r&   r   )r   Zprivate_keyr(   r   r   r   r   r   r   [   s    

zRSASigner.__init__c                 C   s   | j jS r   )r   r(   )r   r   r   r   r(   e   s    zRSASigner.key_idc                 C   s   | j |S r   )r   sign)r   r   r   r   r   r)   j   s    zRSASigner.signc                 C   s    |  | }tjj||d|_|S )a  Construct a Signer instance from a private key in PEM format.

        Args:
            key (str): Private key in PEM format.
            key_id (str): An optional key id used to identify the private key.

        Returns:
            google.auth.crypt.Signer: The constructed signer.

        Raises:
            ValueError: If the key cannot be parsed as PKCS#1 or PKCS#8 in
                PEM format.
        r'   )r   r   r&   r   r   )r   keyr(   r   r   r   r   r   n   s    
zRSASigner.from_string)N)N)r    r
   r!   r"   r   propertyr   r#   r   Signerr(   r)   r%   r   r   r   r   r   r&   M   s   




r&   N)r"   Z-cryptography.hazmat.primitives.asymmetric.rsar   r   Zgoogle.authr   Zgoogle.auth.cryptr   r   r   r   r$   r   r,   ZFromServiceAccountMixinr&   r   r   r   r   <module>   s   ,