
    kCiB                     x   S r SSKJr  SSKJrJrJr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\R6                  " 5       r\R:                  " 5       r\ " S S5      5       r " S S\R@                  5      r! " S S\RD                  \RF                  5      r$g)zAECDSA verifier and signer that use the ``cryptography`` library.
    )	dataclass)AnyDictOptionalUnionN)backends)hashes)serialization)ec)padding)decode_dss_signature)encode_dss_signature)_helpers)bases   -----BEGIN CERTIFICATE-----c                       \ rS rSr% Sr\\S'   \R                  \S'   \	\S'   \
S\\R                  \R                  4   4S j5       r\
S\R                   4S	 j5       rS
rg)_ESAttributes(   zA class that models ECDSA attributes.

Attributes:
    rs_size (int): Size for ASN.1 r and s size.
    sha_algo (hashes.HashAlgorithm): Hash algorithm.
    algorithm (str): Algorithm name.
rs_sizesha_algo	algorithmkeyc                 8    U R                  UR                  5      $ N)
from_curvecurve)clsr   s     P/var/www/html/land-ocr/venv/lib/python3.13/site-packages/google/auth/crypt/es.pyfrom_key_ESAttributes.from_key6   s     ~~cii((    r   c                     [        U[        R                  5      (       a  U " S[        R                  " 5       S5      $ U " S[        R
                  " 5       S5      $ )N0   ES384    ES256)
isinstancer   	SECP384R1r	   SHA384SHA256)r   r   s     r   r   _ESAttributes.from_curve<   sA     eR\\**r6==?G44 r6==?G44r     N)__name__
__module____qualname____firstlineno____doc__int__annotations__r	   HashAlgorithmstrclassmethodr   r   EllipticCurvePublicKeyEllipticCurvePrivateKeyr   EllipticCurver   __static_attributes__r+   r    r   r   r   (   sp     L"""N)1123M3MMN) )
 	5r// 	5 	5r    r   c                       \ rS rSrSrS\R                  SS4S jr\R                  " \
R                  5      S\S\S\4S	 j5       r\S\\\4   SS 4S
 j5       rSrg)
EsVerifierI   zVerifies ECDSA cryptographic signatures using public keys.

Args:
    public_key (
            cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey):
        The public key used to verify signatures.

public_keyreturnNc                 D    Xl         [        R                  U5      U l        g r   )_pubkeyr   r   _attributes)selfr=   s     r   __init__EsVerifier.__init__R   s    !(11*=r    message	signaturec                 H   [         R                  " U5      n[        U5      U R                  R                  S-  :w  a  g[
        R                  US U R                  R                   SS9n[
        R                  X0R                  R                  S  SS9n[        XE5      n[         R                  " U5      n U R                  R                  Xa[        R                  " U R                  R                  5      5        g! [        [        R                  R                   4 a     gf = f)N   Fbig	byteorderT)r   to_byteslenrA   r   r1   
from_bytesr   r@   verifyr   ECDSAr   
ValueErrorcryptography
exceptionsInvalidSignature)rB   rE   rF   	sig_bytesrsasn1_sigs          r   rO   EsVerifier.verifyV   s     %%i0	y>T--5599NN9%?t'7'7'?'?@ENRNN9%5%5%=%=%?@ENR'-##G,	LL288D<L<L<U<U3VWL33DDE 		s   5AC: :$D! D!c                 F   [         R                  " U5      n[        U;   a5  [        R                  R                  U[        5      nUR                  5       nO[        R                  " U[        5      n[        U[        R                  5      (       d  [        S5      e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.
z2Expected public key of type EllipticCurvePublicKey)r   rL   _CERTIFICATE_MARKERrR   x509load_pem_x509_certificate_BACKENDr=   r
   load_pem_public_keyr&   r   r6   	TypeError)r   r=   public_key_datacertpubkeys        r   from_stringEsVerifier.from_stringg   s     #++J7/1$$>>D __&F #66QF&"";";<<PQQ6{r    )rA   r@   )r,   r-   r.   r/   r0   r   r6   rC   r   copy_docstringr   VerifierbytesboolrO   r5   r   r4   rd   r9   r+   r    r   r;   r;   I   s    >2#<#< > > T]]+e  $  ,  U3:%6 <  r    r;   c                   |   \ rS rSrSr SS\R                  S\\   SS4S jjr	\
S\4S j5       r\
\R                  " \R                  5      S\\   4S	 j5       5       r\R                  " \R                  5      S
\S\4S j5       r\ SS\\\4   S\\   SS 4S jj5       rS\\\4   4S jrS\\\4   SS4S jrSrg)EsSigner   ap  Signs messages with an ECDSA private key.

Args:
    private_key (
            cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey):
        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.
Nprivate_keykey_idr>   c                 P    Xl         X l        [        R                  U5      U l        g r   )_key_key_idr   r   rA   )rB   rm   rn   s      r   rC   EsSigner.__init__   s!      	(11+>r    c                 .    U R                   R                  $ )zSName of the algorithm used to sign messages.
Returns:
    str: The algorithm name.
)rA   r   rB   s    r   r   EsSigner.algorithm   s     )))r    c                     U R                   $ r   )rq   rt   s    r   rn   EsSigner.key_id   s     ||r    rE   c                 b   [         R                  " U5      nU R                  R                  U[        R
                  " U R                  R                  5      5      n[        U5      u  p4UR                  U R                  R                  SS9UR                  U R                  R                  SS9-   $ )NrI   rJ   )
r   rL   rp   signr   rP   rA   r   r   r   )rB   rE   asn1_signaturerV   rW   s        r   ry   EsSigner.sign   s    ##G,$:J:J:S:S1TU &n5zz$**22ezDqzz$$ HR H
 
 	
r    r   c                     [         R                  " U5      n[        R                  " US[        S9n[        U[        R                  5      (       d  [        S5      eU " XBS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backendz4Expected private key of type EllipticCurvePrivateKey)rn   )	r   rL   r
   load_pem_private_keyr^   r&   r   r7   r`   )r   r   rn   	key_bytesrm   s        r   rd   EsSigner.from_string   sW    ( %%c*	#88h
 +r'A'ABBRSS;..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_algorithmrp   )
__dict__copyrp   private_bytesr
   EncodingPEMPrivateFormatPKCS8NoEncryptionrB   states     r   __getstate__EsSigner.__getstate__   sb    ""$		//"++// ..44!.!;!;!= 0 
f
 r    r   c                 t    [         R                  " US   S5      US'   U R                  R                  U5        g)z3Pickle helper that deserializes the _key attribute.rp   N)r
   r   r   updater   s     r   __setstate__EsSigner.__setstate__   s.    %::5=$OfU#r    )rA   rp   rq   r   )r,   r-   r.   r/   r0   r   r7   r   r4   rC   propertyr   r   rf   r   Signerrn   rh   ry   r5   r   rd   r   r   r   r   r9   r+   r    r   rk   rk      s"   	 PT?55??G}?	? *3 * * T[[)  *  T[[)
E 
e 
 *
 =A/s
#/-5c]/	/ /:d38n $$sCx. $T $r    rk   )%r0   dataclassesr   typingr   r   r   r   cryptography.exceptionsrR   cryptography.hazmatr   cryptography.hazmat.primitivesr	   r
   )cryptography.hazmat.primitives.asymmetricr   r   /cryptography.hazmat.primitives.asymmetric.utilsr   r   cryptography.x509google.authr   google.auth.cryptr   r[   default_backendr^   PKCS1v15_PADDINGr   rg   r;   r   FromServiceAccountMixinrk   r+   r    r   <module>r      s    " - -  ( 1 8 8 = P P    " 5 ##% 5 5 5@; ;|V$t{{D88 V$r    