
                         p    S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
   " S S\5      r " S	 S
\5      rg)z2pyCrypto Crypto-related routines for oauth2client.    )SHA256)RSA)
PKCS1_v1_5)DerSequence)_helpersc                   4    \ rS rSrSrS rS r\S 5       rSr	g)PyCryptoVerifier   z$Verifies the signature on a message.c                     Xl         g)zcConstructor.

Args:
    pubkey: OpenSSL.crypto.PKey (or equiv), The public key to verify
    with.
N_pubkey)selfpubkeys     /lib/third_party/oauth2client/_pycrypto_crypt.py__init__PyCryptoVerifier.__init__   s	         c                     [         R                  " USS9n[        R                  " U R                  5      R                  [        R                  " U5      U5      $ )ac  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   PyCryptoVerifier.verify$   sD     $$Ww?~~dll+22JJw, 	,r   c                    U(       a  [         R                  " U 5      n U R                  SS5      R                  5       n[         R                  " SR                  USS 5      5      n[        5       nUR                  U5        [        5       nUR                  US   5        [        R                  " US   5      nO[        R                  " U 5      n[        U5      $ )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_stringPyCryptoVerifier.from_string4   s     ((1GtS1779H11#((8Ab>2JKG!mGNN7# ]FMM'!*%]]6!9-F]]7+F''r   r   N)
__name__
__module____qualname____firstlineno____doc__r   r   staticmethodr/   __static_attributes__ r   r   r	   r	      s#    .,  ( (r   r	   c                   8    \ rS rSrSrS rS r\SS j5       rSr	g)	PyCryptoSignerN   z"Signs messages with a private key.c                     Xl         g)z\Constructor.

Args:
    pkey, OpenSSL.crypto.PKey (or equiv), The private key to sign with.
N_key)r   pkeys     r   r   PyCryptoSigner.__init__Q   s	     	r   c                     [         R                  " USS9n[        R                  " U R                  5      R                  [        R                  " U5      5      $ )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   r>   signr   )r   r   s     r   rB   PyCryptoSigner.signY   s=     $$Ww?~~dii(--fjj.ABBr   c                     [         R                  " [         R                  " U 5      5      nU(       a  [        R                  " U5      nO[        S5      e[        U5      $ )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(   NotImplementedErrorr:   )keypasswordparsed_pem_keyr?   s       r   r/   PyCryptoSigner.from_stringe   sO     "001C1CC1HI==0D%  d##r   r=   N)
notasecret)
r1   r2   r3   r4   r5   r   rB   r6   r/   r7   r8   r   r   r:   r:   N   s$    ,
C $ $r   r:   N)r5   Crypto.Hashr   Crypto.PublicKeyr   Crypto.Signaturer   Crypto.Util.asn1r   oauth2clientr   objectr	   r:   r8   r   r   <module>rR      s2    9    ' ( !3(v 3(l.$V .$r   