o
    M,hR                     @   s   d dl Z d dlmZmZ d dlmZ d dlmZmZ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)Enum)AnyOptionalUnionc                   @   s   e Zd ZdZdZdZdS )Protocolz/Protocol to communicate with the authenticator.ctap2z	ctap1/u2fN)__name__
__module____qualname____doc__CTAP2U2F r   r   {/var/www/www-root/data/www/bot.pdev.uz/venv/lib/python3.10/site-packages/selenium/webdriver/common/virtual_authenticator.pyr      s    r   c                   @   s    e Zd ZdZdZdZdZdZdS )	Transportz7Transport method to communicate with the authenticator.bleusbnfcinternalN)r
   r   r   r   BLEUSBNFCINTERNALr   r   r   r   r      s    r   c                   @   sj   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
ee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_dictC   s   z#VirtualAuthenticatorOptions.to_dict)r
   r   r   r   r   r   r   strboolr&   dictr   r,   r   r   r   r   r   (   s2    
"r   c                   @   s4  e Zd Zdededee de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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e deded	d fddZd	eeef fddZedeee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#   )ar  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): initial 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&   O   s   
zCredential.__init__r"   c                 C      t | j S N)r   r7   decoder+   r   r   r   idj      zCredential.idc                 C      | j S r>   )r8   r+   r   r   r   r2   n      z!Credential.is_resident_credentialc                 C   rB   r>   )r9   r+   r   r   r   r3   r   rC   zCredential.rp_idc                 C   s   | j r
t| j  S d S r>   )r:   r   r?   r+   r   r   r   r4   v   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): initial 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): initial 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-   rP   r&   propertyr@   r2   r3   r4   r5   r6   classmethodrE   rF   r/   r   r,   rQ   rS   r   r   r   r   r0   N   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r`   ra   r   r_   r   required_chromium_based_browser   s   re   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\   r_   r   r   ra      s   z/required_virtual_authenticator.<locals>.wrapper)rb   rc   re   rd   r   r_   r   required_virtual_authenticator   s   rh   )rb   base64r   r   enumr   typingr   r   r   r-   r   r   r   r0   re   rh   r   r   r   r   <module>   s   	&u