
    (phk                     B   S r SSKJr  SSK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	KJr  SS
KJr  SSKrSSKJr  SSKJr  Sr\R*                  " 5       r\R.                  " 5       r " S S\R2                  5      r " S S\R6                  \R8                  5      rg)zIECDSA (ES256) verifier and signer that use the ``cryptography`` library.
    )utilsN)backends)hashes)serialization)ec)padding)decode_dss_signature)encode_dss_signature)_helpers)bases   -----BEGIN CERTIFICATE-----c                   r    \ rS rSrSrS r\R                  " \R                  5      S 5       r
\S 5       rSrg)ES256Verifier&   zVerifies ECDSA cryptographic signatures using public keys.

Args:
    public_key (
            cryptography.hazmat.primitives.asymmetric.ec.ECDSAPublicKey):
        The public key used to verify signatures.
c                     Xl         g N_pubkey)self
public_keys     J/var/www/html/venv/lib/python3.13/site-packages/google/auth/crypt/es256.py__init__ES256Verifier.__init__/   s    !    c                    [         R                  " U5      n[        U5      S:w  a  g[         R                  " 5       (       a  [        R                  US S SS9O[        R                  " US S SS9n[         R                  " 5       (       a  [        R                  USS  SS9O[        R                  " USS  SS9n[        XE5      n[         R                  " U5      n U R                  R                  Xa[        R                  " [        R                  " 5       5      5        g! [        [         R"                  R$                  4 a     gf = f)N@   F    big	byteorderT)r   to_byteslenis_python_3int
from_bytesr   int_from_bytesr
   r   verifyr   ECDSAr   SHA256
ValueErrorcryptography
exceptionsInvalidSignature)r   message	signature	sig_bytesrsasn1_sigs          r   r&   ES256Verifier.verify2   s    %%i0	y>R ##%% NN9Sb>UN;%%inF 	
 ##%% NN9RS>UN;%%inF 	

 (-##G,	LL288FMMO3LML33DDE 		s   AD $EEc                     [         R                  " U5      n[        U;   a5  [        R                  R                  U[        5      nUR                  5       nO[        R                  " U[        5      nU " U5      $ )a1  Construct an 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:
    Verifier: The constructed verifier.

Raises:
    ValueError: If the public key can't be parsed.
)
r   r    _CERTIFICATE_MARKERr*   x509load_pem_x509_certificate_BACKENDr   r   load_pem_public_key)clsr   public_key_datacertpubkeys        r   from_stringES256Verifier.from_stringK   sc     #++J7/1$$>>D __&F #66QF6{r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   copy_docstringr   Verifierr&   classmethodr>   __static_attributes__ r   r   r   r   &   sC    " T]]+ ,0  r   r   c                       \ rS rSrSrSS jr\\R                  " \	R                  5      S 5       5       r\R                  " \	R                  5      S 5       r\SS j5       rS rS	 rS
rg)ES256Signerh   ah  Signs messages with an ECDSA private key.

Args:
    private_key (
            cryptography.hazmat.primitives.asymmetric.ec.ECDSAPrivateKey):
        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.
Nc                     Xl         X l        g r   _key_key_id)r   private_keykey_ids      r   r   ES256Signer.__init__t   s    	r   c                     U R                   $ r   )rP   )r   s    r   rR   ES256Signer.key_idx   s     ||r   c                    [         R                  " U5      nU R                  R                  U[        R
                  " [        R                  " 5       5      5      n[        U5      u  p4[         R                  " 5       (       a!  UR                  SSS9UR                  SSS9-   $ [        R                  " US5      [        R                  " US5      -   $ )Nr   r   r   )r   r    rO   signr   r'   r   r(   r	   r"   r   int_to_bytes)r   r-   asn1_signaturer0   r1   s        r   rW   ES256Signer.sign}   s    ##G,&--/1JK &n5 ##%% ZZeZ,qzz"z/NN	
 $$Q+e.@.@B.GG	
r   c                 n    [         R                  " U5      n[        R                  " US[        S9nU " X2S9$ )a  Construct a RSASigner from a private key in PEM format.

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

Returns:
    google.auth.crypt._cryptography_rsa.RSASigner: The
    constructed signer.

Raises:
    ValueError: If ``key`` is not ``bytes`` or ``str`` (unicode).
    UnicodeDecodeError: If ``key`` is ``bytes`` but cannot be decoded
        into a UTF-8 ``str``.
    ValueError: If ``cryptography`` "Could not deserialize key data."
N)passwordbackend)rR   )r   r    r   load_pem_private_keyr8   )r:   keyrR   rQ   s       r   r>   ES256Signer.from_string   s8    $ $#88$
 ;..r   c                     U R                   R                  5       nU R                  R                  [        R
                  R                  [        R                  R                  [        R                  " 5       S9US'   U$ )z1Pickle helper that serializes the _key attribute.)encodingformatencryption_algorithmrO   )
__dict__copyrO   private_bytesr   EncodingPEMPrivateFormatPKCS8NoEncryptionr   states     r   __getstate__ES256Signer.__getstate__   sb    ""$		//"++// ..44!.!;!;!= 0 
f
 r   c                 t    [         R                  " US   S5      US'   U R                  R                  U5        g)z3Pickle helper that deserializes the _key attribute.rO   N)r   r^   re   updaterm   s     r   __setstate__ES256Signer.__setstate__   s.    %::5=$OfU#r   rN   r   )r@   rA   rB   rC   rD   r   propertyr   rE   r   SignerrR   rW   rG   r>   ro   rs   rH   rI   r   r   rK   rK   h   sx    	 T[[) *  T[[)

 *

 / /.$r   rK   )rD   r*   r   cryptography.exceptionscryptography.hazmatr   cryptography.hazmat.primitivesr   r   )cryptography.hazmat.primitives.asymmetricr   r   /cryptography.hazmat.primitives.asymmetric.utilsr	   r
   cryptography.x509google.authr   google.auth.cryptr   r5   default_backendr8   PKCS1v15_PADDINGrF   r   rv   FromServiceAccountMixinrK   rI   r   r   <module>r      s      ( 1 8 8 = P P    " 5 ##%?DMM ?DG$$++t;; G$r   