a
    xd                     @   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.Zctap2CTAP2z	ctap1/u2fU2FN)__name__
__module____qualname____doc__r   str__annotations__r    r   r   g/var/www/html/Ranjet/env/lib/python3.9/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.ZbleBLEZusbUSBZnfcNFCZinternalINTERNALN)
r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r       s
   
r   c                	   @   sb   e Zd ZeZeZejejddddfeeeeeeddddZ	e
jee
jeef f ddd	ZdS )
VirtualAuthenticatorOptionsFTN)protocol	transporthas_resident_keyhas_user_verificationis_user_consentingis_user_verifiedreturnc                 C   s(   || _ || _|| _|| _|| _|| _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__r   c                 C   s   | j | j| j| j| j| jdS )N)r   r   ZhasResidentKeyZhasUserVerificationZisUserConsentingZ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   )   s$   r   c                   @   s   e Zd Zeeeeje eedddZ	e
edddZe
edddZe
edd	d
Ze
eje dddZe
edddZe
edddZeeeeed dddZeeeeje eed dddZejeejf dddZeejeejf d dddZedddZdS )
Credential)credential_idis_resident_credentialrp_iduser_handleprivate_key
sign_countc                 C   s(   || _ || _|| _|| _|| _|| _dS )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   r(   r)   r*   r+   r,   r-   r   r   r   r   P   s    zCredential.__init__r    c                 C   s   t | j S N)r   r.   decoder!   r   r   r   idk   s    zCredential.idc                 C   s   | j S r4   )r/   r!   r   r   r   r)   o   s    z!Credential.is_resident_credentialc                 C   s   | j S r4   )r0   r!   r   r   r   r*   s   s    zCredential.rp_idc                 C   s   | j rt| j  S d S r4   )r1   r   r5   r!   r   r   r   r+   w   s    zCredential.user_handlec                 C   s   t | j S r4   )r   r2   r5   r!   r   r   r   r,   }   s    zCredential.private_keyc                 C   s   | j S r4   )r3   r!   r   r   r   r-      s    zCredential.sign_count)r6   r*   r,   r-   r   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   )clsr6   r*   r,   r-   r   r   r   create_non_resident_credential   s    z)Credential.create_non_resident_credential)r6   r*   r+   r,   r-   r   c                 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   )r7   r6   r*   r+   r,   r-   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)r6   r/   r*   r,   r-   r+   )r   Zcredential_datar   r   r   r"      s    
zCredential.to_dict)datar   c                 C   s|   t |d  d}t|d }|dd }t |d  d}t|d }|dd rft |d  dnd }| ||||||S )Nr:   z==r;   r<   r=   r>   r?   )r   r#   getint)r7   r@   r.   r)   r*   r,   r-   r+   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=))r6   r)   r*   r+   r,   r-   r!   r   r   r   __str__   s    zCredential.__str__N)r   r	   r
   bytesr#   r   r$   OptionalrB   r   propertyr6   r)   r*   r+   r,   r-   classmethodr8   r9   r%   Anyr"   rC   rE   r   r   r   r   r'   O   s:   
r'   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 )NZbrowserName)ZfirefoxZsafariz4This only currently works in Chromium based browsers)Zcapslowerr   argskwargsfuncr   r   wrapper   s    z0required_chromium_based_browser.<locals>.wrapper)	functoolswrapsrP   rQ   r   rO   r   required_chromium_based_browser   s    rU   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.)Zvirtual_authenticator_id
ValueErrorrL   rO   r   r   rQ      s    z/required_virtual_authenticator.<locals>.wrapper)rR   rS   rU   rT   r   rO   r   required_virtual_authenticator   s    rW   )rR   r$   base64r   r   enumr   r   r   r   r   r'   rU   rW   r   r   r   r   <module>   s   	&u