
    Dj                        d dl mZ 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 e G d de                      Z G d d	ej                  Z G d
 de          ZdS )    )annotationsN)IntEnumunique)Event)CallableIteratorcastc                      e Zd ZdZdZdZdS )STATUSz(Status code for CTAP keep-alive message.      N)__name__
__module____qualname____doc__
PROCESSINGUPNEEDED     E/home/thesage/.hermes/venv/lib/python3.11/site-packages/fido2/ctap.pyr   r   $   s        22JHHHr   r   c                      e Zd ZdZeej        dd                        Zej        	 	 	 ddd            ZddZ	d Z
d Zeej        dd                        ZdS )
CtapDevicez
    CTAP-capable device.

    Subclasses of this should implement :func:`call`, as well as :func:`list_devices`,
    which should return a generator over discoverable devices.
    returnintc                    dS )zGet device capabilitiesNr   selfs    r   capabilitieszCtapDevice.capabilities4         r   r   NcmddatabyteseventEvent | Noneon_keepaliveCallable[[STATUS], None] | Nonec                    dS )a)  Sends a command to the authenticator, and reads the response.

        :param cmd: The integer value of the command.
        :param data: The payload of the command.
        :param event: An optional threading.Event which can be used to cancel
            the invocation.
        :param on_keepalive: An optional callback to handle keep-alive messages
            from the authenticator. The function is only called once for
            consecutive keep-alive messages with the same status.
        :return: The response from the authenticator.
        Nr   )r   r    r!   r#   r%   s        r   callzCtapDevice.call9   r   r   Nonec                    dS )z/Close the device, releasing any held resources.Nr   r   s    r   closezCtapDevice.closeM   r   r   c                    | S Nr   r   s    r   	__enter__zCtapDevice.__enter__P   s    r   c                .    |                                   d S r-   )r+   )r   typvalue	tracebacks       r   __exit__zCtapDevice.__exit__S   s    

r   Iterator[CtapDevice]c                    dS )z4Generates instances of cls for discoverable devices.Nr   )clss    r   list_deviceszCtapDevice.list_devicesV   r   r   r   r   )r   NN)
r    r   r!   r"   r#   r$   r%   r&   r   r"   )r   r)   )r   r4   )r   r   r   r   propertyabcabstractmethodr   r(   r+   r.   r3   classmethodr7   r   r   r   r   r   ,   s          & & &  X& 	 "8<    &> > > >     C C C  [C C Cr   r   c                  l     e Zd ZdZ G d de          Ze G d de                      Zd	 fdZ	 xZ
S )
	CtapErrorz;Error returned from the Authenticator when a command fails.c                  :    e Zd ZdZdZed	d            Zd Zd ZdS )
CtapError.UNKNOWN_ERRz.CTAP error status code that is not recognized.UNKNOWN_ERRr   r   c                     t          |           S r-   )r   r   s    r   r1   zCtapError.UNKNOWN_ERR.valued   s    t99r   c                    d| z  S )Nz<ERR.UNKNOWN: %d>r   r   s    r   __repr__zCtapError.UNKNOWN_ERR.__repr__h   s    &--r   c                    d| ddS )N0x02Xz
 - UNKNOWNr   r   s    r   __str__zCtapError.UNKNOWN_ERR.__str__k   s    ,,,,,,r   Nr8   )	r   r   r   r   namer9   r1   rD   rH   r   r   r   rA   r@   _   s[        <<		 	 	 
		. 	. 	.	- 	- 	- 	- 	-r   rA   c                      e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)d(Z*d)Z+d*Z,d+Z-d,Z.d-Z/d.Z0d/Z1d0Z2d1Z3d2Z4d3Z5d4Z6d5Z7d6 Z8d7S )8CtapError.ERRzCTAP status codes.

        https://fidoalliance.org/specs/fido-v2.1-rd-20201208/fido-client-to-authenticator-protocol-v2.1-rd-20201208.html#error-responses
        r   r   r               
                           !   "   #   $   %   &   '   (   +   ,   -   .   /   0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ?   @                     c                (    d| j         dd| j         S )NrF   rG   z - )r1   rI   r   s    r   rH   zCtapError.ERR.__str__   s    6
66649666r   N)9r   r   r   r   SUCCESSINVALID_COMMANDINVALID_PARAMETERINVALID_LENGTHINVALID_SEQTIMEOUTCHANNEL_BUSYLOCK_REQUIREDINVALID_CHANNELCBOR_UNEXPECTED_TYPEINVALID_CBORMISSING_PARAMETERLIMIT_EXCEEDEDFP_DATABASE_FULLLARGE_BLOB_STORAGE_FULLCREDENTIAL_EXCLUDEDr   INVALID_CREDENTIALUSER_ACTION_PENDINGOPERATION_PENDINGNO_OPERATIONSUNSUPPORTED_ALGORITHMOPERATION_DENIEDKEY_STORE_FULLUNSUPPORTED_OPTIONINVALID_OPTIONKEEPALIVE_CANCELNO_CREDENTIALSUSER_ACTION_TIMEOUTNOT_ALLOWEDPIN_INVALIDPIN_BLOCKEDPIN_AUTH_INVALIDPIN_AUTH_BLOCKEDPIN_NOT_SETPUAT_REQUIREDPIN_POLICY_VIOLATIONPIN_TOKEN_EXPIREDREQUEST_TOO_LARGEACTION_TIMEOUTUP_REQUIRED
UV_BLOCKEDINTEGRITY_FAILUREINVALID_SUBCOMMAND
UV_INVALIDUNAUTHORIZED_PERMISSIONOTHER	SPEC_LASTEXTENSION_FIRSTEXTENSION_LASTVENDOR_FIRSTVENDOR_LASTrH   r   r   r   ERRrK   n   sK       	 	
  # "&"
!"  $ ""#  
 !
"&		7 	7 	7 	7 	7r   r   coder   c                *   	 t                               |          | _        nG# t          $ r: t	          t           j        t                               |                    | _        Y nw xY wt                                          d| j                    d S )NzCTAP error: )r>   r   r   
ValueErrorr	   rA   super__init__)r   r   	__class__s     r   r   zCtapError.__init__   s    	I!d++DII 	I 	I 	IY]I,A,A$,G,GHHDIII	I3	3344444s   # AA'&A')r   r   )r   r   r   r   r   rA   r   r   r   r   __classcell__)r   s   @r   r>   r>   \   s        EE- - - - -c - - - ?7 ?7 ?7 ?7 ?7g ?7 ?7 V?7B5 5 5 5 5 5 5 5 5 5r   r>   )
__future__r   r:   enumr   r   	threadingr   typingr   r   r	   r   ABCr   	Exceptionr>   r   r   r   <module>r      s  8 # " " " " " 



                       + + + + + + + + + +     W   -C -C -C -C -C -C -C -C`Y5 Y5 Y5 Y5 Y5	 Y5 Y5 Y5 Y5 Y5r   