
    $)f                         d dl Z d dlZd dlmZ d dlmZ d dlmZ  G d dee      Z G d dee      Z	 G d	 d
      Z
 G d d      Zd Zd Zy)    N)urlsafe_b64decode)urlsafe_b64encode)Enumc                   .    e Zd ZU dZdZeed<   dZeed<   y)Protocolz/Protocol to communicate with the authenticator.ctap2CTAP2z	ctap1/u2fU2FN)__name__
__module____qualname____doc__r	   str__annotations__r
        l/var/www/html/flask-app/venv/lib/python3.12/site-packages/selenium/webdriver/common/virtual_authenticator.pyr   r      s    9E3Cr   r   c                   J    e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	eed	<   y
)	Transportz7Transport method to communicate with the authenticator.bleBLEusbUSBnfcNFCinternalINTERNALN)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r       s-    ACCCHcr   r   c                       e Zd ZeZeZej
                  ej                  ddddfdedededededed	d
fdZ	d	e
j                  ee
j                  eef   f   fdZy
)VirtualAuthenticatorOptionsFTprotocol	transporthas_resident_keyhas_user_verificationis_user_consentingis_user_verifiedreturnNc                 X    || _         || _        || _        || _        || _        || _        y)zMConstructor.

        Initialize VirtualAuthenticatorOptions object.
        Nr    r!   r"   r#   r$   r%   )selfr    r!   r"   r#   r$   r%   s          r   __init__z$VirtualAuthenticatorOptions.__init__/   s2     &'&6+@"(:&6r   c                     | j                   | j                  | j                  | j                  | j                  | j
                  dS )N)r    r!   hasResidentKeyhasUserVerificationisUserConsentingisUserVerifiedr(   r)   s    r   to_dictz#VirtualAuthenticatorOptions.to_dictD   s>    "33#'#=#= $ 7 7"33
 	
r   )r   r   r   r   r   r	   r   r   boolr*   typingDictUnionr1   r   r   r   r   r   )   s     HI !"!&&+#'!&77 7 	7
  $7 !7 7 
7*
S&,,sDy*A%AB 
r   r   c                      e Zd Zdedededej                  e   dedefdZ	e
defd	       Ze
defd
       Ze
defd       Ze
dej                  e   fd       Ze
defd       Ze
defd       Zedededededd f
d       Zedededej                  e   dededd fd       Zdej(                  eej*                  f   fdZedej(                  eej*                  f   dd fd       ZdefdZy)
Credentialcredential_idis_resident_credentialrp_iduser_handleprivate_key
sign_countc                 X    || _         || _        || _        || _        || _        || _        y)ah  Constructor. A credential stored in a virtual authenticator.
        https://w3c.github.io/webauthn/#credential-parameters.

        :Args:
            - credential_id (bytes): Unique base64 encoded string.
            is_resident_credential (bool): Whether the credential is client-side discoverable.
            rp_id (str): Relying party identifier.
            user_handle (bytes): userHandle associated to the credential. Must be Base64 encoded string. Can be None.
            private_key (bytes): Base64 encoded PKCS#8 private key.
            sign_count (int): intital value for a signature counter.
        N)_id_is_resident_credential_rp_id_user_handle_private_key_sign_count)r)   r8   r9   r:   r;   r<   r=   s          r   r*   zCredential.__init__P   s2    ( !'=$''%r   r&   c                 H    t        | j                        j                         S N)r   r?   decoder0   s    r   idzCredential.idk   s     *1133r   c                     | j                   S rF   )r@   r0   s    r   r9   z!Credential.is_resident_credentialo   s    +++r   c                     | j                   S rF   )rA   r0   s    r   r:   zCredential.rp_ids   s    {{r   c                 b    | j                   r#t        | j                         j                         S y rF   )rB   r   rG   r0   s    r   r;   zCredential.user_handlew   s(    $T%6%67>>@@r   c                 H    t        | j                        j                         S rF   )r   rC   rG   r0   s    r   r<   zCredential.private_key}   s     !2!23::<<r   c                     | j                   S rF   )rD   r0   s    r   r=   zCredential.sign_count   s    r   rH   c                      | |d|d||      S )au  Creates a non-resident (i.e. stateless) credential.

        :Args:
          - id (bytes): Unique base64 encoded string.
          - rp_id (str): Relying party identifier.
          - private_key (bytes): Base64 encoded PKCS
          - sign_count (int): intital value for a signature counter.

        :Returns:
          - Credential: A non-resident credential.
        FNr   )clsrH   r:   r<   r=   s        r   create_non_resident_credentialz)Credential.create_non_resident_credential   s     2ueT;
CCr   c                      | |d||||      S )a  Creates a resident (i.e. stateful) credential.

        :Args:
          - id (bytes): Unique base64 encoded string.
          - rp_id (str): Relying party identifier.
          - user_handle (bytes): userHandle associated to the credential. Must be Base64 encoded string.
          - private_key (bytes): Base64 encoded PKCS
          - sign_count (int): intital value for a signature counter.

        :returns:
          - Credential: A resident credential.
        Tr   )rO   rH   r:   r;   r<   r=   s         r   create_resident_credentialz%Credential.create_resident_credential   s      2tUKjIIr   c                     | j                   | j                  | j                  | j                  | j                  d}| j
                  r| j
                  |d<   |S )N)credentialIdisResidentCredentialrpId
privateKey	signCount
userHandle)rH   r@   r:   r<   r=   r;   )r)   credential_datas     r   r1   zCredential.to_dict   sQ     GG$($@$@JJ**
 ,0,<,<OL)r   datac                    t        |d    d      }t        |d         }|j                  dd       }t        |d    d      }t        |d         }|j                  dd       rt        |d    d      nd } | ||||||      S )NrT   z==rU   rV   rW   rX   rY   )r   r2   getint)rO   r[   r?   r9   r:   r<   r=   r;   s           r   	from_dictzCredential.from_dict   s    4#7"8 ;<!%d+A&B!C&'4+=*>b(ABk*+
FJhh|]aFb'4+=*>b(ABhl3.{KQ[\\r   c                     d| j                    d| j                   d| j                   d| j                   d| j                   d| j
                   dS )NzCredential(id=z, is_resident_credential=z, rp_id=z,            user_handle=z, private_key=z, sign_count=))rH   r9   r:   r;   r<   r=   r0   s    r   __str__zCredential.__str__   sf    y(A$B]B]A^^fgkgqgqfr s))*.9I9I8J-X\XgXgWhhik 	kr   N)r   r   r   bytesr2   r   r3   Optionalr^   r*   propertyrH   r9   r:   r;   r<   r=   classmethodrP   rR   r4   Anyr1   r_   rb   r   r   r   r7   r7   O   s   && !%& 	&
 __U+& & &6 4C 4 4 , , , s   V__S1  
 =S = =  C     D Dc DPU Dcf Dkw D D JJ"J171GJV[JilJ	J J"S&**_5  ]V[[fjj9 ]l ] ]k kr   r7   c                 B     t        j                          fd       }|S )zKA decorator to ensure that the client used is a chromium based
    browser.c                 h    | j                   d   j                         dvsJ d        | g|i |S )NbrowserName)firefoxsafariz4This only currently works in Chromium based browsers)capslowerr)   argskwargsfuncs      r   wrapperz0required_chromium_based_browser.<locals>.wrapper   sK    yy'--/ 8
 
 	B B	B D*4*6**r   )	functoolswrapsrr   rs   s   ` r   required_chromium_based_browserrw      s'     __T+ + Nr   c                 T     t        j                         t         fd              }|S )zSA decorator to ensure that the function is called with a virtual
    authenticator.c                 J    | j                   st        d       | g|i |S )Nz9This function requires a virtual authenticator to be set.)virtual_authenticator_id
ValueErrorro   s      r   rs   z/required_virtual_authenticator.<locals>.wrapper   s/     ,,XYYD*4*6**r   )rt   ru   rw   rv   s   ` r   required_virtual_authenticatorr|      s/     __T$+ % +
 Nr   )rt   r3   base64r   r   enumr   r   r   r   r   r7   rw   r|   r   r   r   <module>r      sV   $   $ $ sD T #
 #
Lrk rkjr   