o
    ѷ6i                     @   s   d dl Z d dlmZ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)Enum)Anyc                   @   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   t/var/www/hoanhtaovolam_webdjango/env/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                   @   sf   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B 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_dictB   s   z#VirtualAuthenticatorOptions.to_dict)r   r	   r
   r   r   r   r   strboolr$   dictr*   r   r   r   r   r   (   s2    
r   c                   @   s8  e Zd ZdedededB dedB 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dB fddZed
edB 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dB 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_idNuser_handleprivate_key
sign_countc                 C   r!   )af  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#   r/   r0   r1   r2   r3   r4   r   r   r   r$   N   s   
zCredential.__init__r    c                 C      t | j S N)r   r5   decoder)   r   r   r   idj      zCredential.idc                 C      | j S r<   )r6   r)   r   r   r   r0   n      z!Credential.is_resident_credentialc                 C   r@   r<   )r7   r)   r   r   r   r1   r   rA   zCredential.rp_idc                 C   s   | j r
t| j  S d S r<   )r8   r   r=   r)   r   r   r   r2   v   s   zCredential.user_handlec                 C   r;   r<   )r   r9   r=   r)   r   r   r   r3   |   r?   zCredential.private_keyc                 C   r@   r<   )r:   r)   r   r   r   r4      rA   zCredential.sign_countr>   c                 C   s   | |d|d||S )as  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>   r1   r3   r4   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   )rB   r>   r1   r2   r3   r4   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>   r6   r1   r3   r4   r2   )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 )NrE   z==rF   rG   rH   rI   rJ   )r   r,   getint)rB   rL   r5   r0   r1   r3   r4   r2   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>   r0   r1   r2   r3   r4   r)   r   r   r   __str__   s   zCredential.__str__)r   r	   r
   bytesr,   r+   rN   r$   propertyr>   r0   r1   r2   r3   r4   classmethodrC   rD   r-   r   r*   rO   rQ   r   r   r   r   r.   M   s\    
 
r.   c                    s   t   fdd}|S )zEDecorator 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^   r_   r   r]   r   required_chromium_based_browser   s   rc   c                    s   t  t fdd}|S )zMDecorator 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
ValueErrorrZ   r]   r   r   r_      s   z/required_virtual_authenticator.<locals>.wrapper)r`   ra   rc   rb   r   r]   r   required_virtual_authenticator   s   rf   )r`   base64r   r   enumr   typingr   r+   r   r   r   r.   rc   rf   r   r   r   r   <module>   s   	%v