o
    ҷh                     @   s   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 deeZG dd deeZ	G d	d
 d
Z
G dd dZdd Zdd ZdS )    N)urlsafe_b64decode)urlsafe_b64encode)Enumc                   @   s*   e Zd ZU dZdZeed< dZeed< dS )Protocolz/Protocol to communicate with the authenticator.ctap2CTAP2z	ctap1/u2fU2FN)__name__
__module____qualname____doc__r   str__annotations__r    r   r   b/var/www/html/venv/lib/python3.10/site-packages/selenium/webdriver/common/virtual_authenticator.pyr      s   
 r   c                   @   sB   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	< d
S )	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   
 r   c                   @   sn   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dZ	d	e
jee
jeef f fddZd
S )VirtualAuthenticatorOptionsFTprotocol	transporthas_resident_keyhas_user_verificationis_user_consentingis_user_verifiedreturnNc                 C   (   || _ || _|| _|| _|| _|| _dS )zMConstructor.

        Initialize VirtualAuthenticatorOptions object.
        Nr   r   r   r   r   r    )selfr   r   r   r   r   r    r   r   r   __init__/   s   
z$VirtualAuthenticatorOptions.__init__c                 C   s   | j | j| j| j| j| jdS )N)r   r   hasResidentKeyhasUserVerificationisUserConsentingisUserVerifiedr#   r$   r   r   r   to_dictD   s   z#VirtualAuthenticatorOptions.to_dict)r	   r
   r   r   r   r   r   r   boolr%   typingDictUnionr+   r   r   r   r   r   )   s2    
&r   c                   @   s>  e Zd Zdedededeje dedefddZ	e
d	efd
dZe
d	efddZe
d	efddZe
d	eje fddZe
d	efddZe
d	efddZededededed	d f
ddZedededeje deded	d fddZd	ejeejf fddZedejeejf d	d fddZd	efd d!Zd"S )#
Credentialcredential_idis_resident_credentialrp_iduser_handleprivate_key
sign_countc                 C   r"   )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$   r1   r2   r3   r4   r5   r6   r   r   r   r%   P   s   
zCredential.__init__r!   c                 C      t | j S N)r   r7   decoder*   r   r   r   idk      zCredential.idc                 C      | j S r>   )r8   r*   r   r   r   r2   o      z!Credential.is_resident_credentialc                 C   rB   r>   )r9   r*   r   r   r   r3   s   rC   zCredential.rp_idc                 C   s   | j r
t| j  S d S r>   )r:   r   r?   r*   r   r   r   r4   w   s   zCredential.user_handlec                 C   r=   r>   )r   r;   r?   r*   r   r   r   r5   }   rA   zCredential.private_keyc                 C   rB   r>   )r<   r*   r   r   r   r6      rC   zCredential.sign_countr@   c                 C   s   | |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   )clsr@   r3   r5   r6   r   r   r   create_non_resident_credential   s   z)Credential.create_non_resident_credentialc                 C   s   | |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   )rD   r@   r3   r4   r5   r6   r   r   r   create_resident_credential   s   z%Credential.create_resident_credentialc                 C   s.   | j | j| j| j| jd}| jr| j|d< |S )N)credentialIdisResidentCredentialrpId
privateKey	signCount
userHandle)r@   r8   r3   r5   r6   r4   )r$   credential_datar   r   r   r+      s   
zCredential.to_dictdatac                 C   s|   t |d  d}t|d }|dd }t |d  d}t|d }|dd r3t |d  dnd }| ||||||S )NrG   z==rH   rI   rJ   rK   rL   )r   r,   getint)rD   rN   r7   r2   r3   r5   r6   r4   r   r   r   	from_dict   s   "zCredential.from_dictc                 C   s6   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=))r@   r2   r3   r4   r5   r6   r*   r   r   r   __str__   s   zCredential.__str__N)r	   r
   r   bytesr,   r   r-   OptionalrP   r%   propertyr@   r2   r3   r4   r5   r6   classmethodrE   rF   r.   Anyr+   rQ   rS   r   r   r   r   r0   O   s\    
  
r0   c                    s   t   fdd}|S )zKA decorator to ensure that the client used is a chromium based
    browser.c                    s0   | j d  dvsJ d | g|R i |S )NbrowserName)firefoxsafariz4This only currently works in Chromium based browsers)capslowerr$   argskwargsfuncr   r   wrapper   s   z0required_chromium_based_browser.<locals>.wrapper)	functoolswrapsrb   rc   r   ra   r   required_chromium_based_browser   s   rg   c                    s   t  t fdd}|S )zSA decorator to ensure that the function is called with a virtual
    authenticator.c                    s$   | j std | g|R i |S )Nz9This function requires a virtual authenticator to be set.)virtual_authenticator_id
ValueErrorr^   ra   r   r   rc      s   z/required_virtual_authenticator.<locals>.wrapper)rd   re   rg   rf   r   ra   r   required_virtual_authenticator   s   rj   )rd   r-   base64r   r   enumr   r   r   r   r   r0   rg   rj   r   r   r   r   <module>   s   	&u