+
     h#  c                  s$   ^ RI Ht ^ RIt^ RIHt ^ RIHtHt ^RIH	t	 ^RI
Ht ^RIHt ^RIHt ^R	IHtHtHtHt ] ! R
 R]4      4       t ! R R]4      t]! RR7       ! R R]4      4       t]! RR7       ! R R]4      4       t ! R R4      tR# )    )annotationsN)	dataclass)IntEnumunique)FidoU2FAttestation)ES256)
CtapDevice)CTAPHID)
ByteBuffer	bytes2intwebsafe_decodewebsafe_encodec                  s&    ] tR t^)tRtRtRtRtRtR# )APDUzAPDU response codes.i   ii  ij   N)	__name__
__module____qualname____firstlineno____doc__OKZUSE_NOT_SATISFIEDZ
WRONG_DATA__static_attributes__r       0/usr/lib/python3.14/site-packages/fido2/ctap1.pyr   r   )   s    	BJr   r   c                  s0    ] tR t^2tRtRR R lltR tRtR# )	ApduErrorzAn Exception thrown when a response APDU doesn't have an OK (0x9000)
status.

:param code: APDU response code.
:param data: APDU response body.

c                    V ^8  d   QhRRRR/# )   codeintdatabytesr   Zformat   "r   __annotate__ZApduError.__annotate__;   s      S  r   c                	s    Wn         W n        R # Nr   r   )selfr   r      &&&r   __init__ZApduError.__init__;   s    		r   c                	sR    R V P                   R R\        V P                  4      R R2# )zAPDU error: 0xZ04XZ Zdz bytes of data)r   lenr   r$      &r   __repr__ZApduError.__repr__?   s(    		#aDIIq/APPr   r#   N)r   )r   r   r   r   r   r&   r*   r   r   r   r   r   r   2   s    Qr   r   F)Zinitc                  s   a  ] tR t^Ct$ RtR]R&   R]R&   R]R&   R]R&   R V 3R llt]R	 R
 l4       tR R lt	]
R R l4       tRtV ;t# )RegistrationDataa[  Binary response data for a CTAP1 registration.

:param _: The binary contents of the response data.
:ivar public_key: Binary representation of the credential public key.
:ivar key_handle: Binary key handle of the credential.
:ivar certificate: Attestation certificate of the authenticator, DER
    encoded.
:ivar signature: Attestation signature.
r   
public_key
key_handlecertificate	signaturec                   V ^8  d   QhRR/# r   _r   r   r   r    r   r!   RegistrationData.__annotate__T   s     ' '% 'r   c                	s  < \         SV `  4        \        V 4      pVP                  R 4      ^8w  d   \	        R4      hVP                  ^A4      V n        VP                  VP                  R 4      4      V n        VP                  ^4      pV^,          pV^8  d.   V^,
          pVP                  V4      pW6,          p\        V4      pW2P                  V4      ,           V n	        VP                  4       V n
        R# )BzReserved byte != 0x05N)superr&   r	   unpackZ
ValueErrorreadr,   r-   r
   r.   r/   )r$   r2   readerZcert_bufZcert_lenZn_bytesZ	len_bytes	__class__s   &&     r   r&   ZRegistrationData.__init__T   s    D!==%455 ++b/ ++fmmC&89;;q>A;d?oGG,I!H +H#kk(&;;r   c               r0   r   returnstrr   r   r    r   r!   r3   i        $ $S $r   c                    \        V 4      # )z6Websafe base64 encoded string of the RegistrationData.r   r(   r)   r   b64ZRegistrationData.b64h        d##r   c               $    V ^8  d   QhRRRRRR/# )r   	app_paramr   client_paramr;   Noner   r   r    r   r!   r3   m   s!     
 
 
U 
t 
r   c                s    \         P                  ! VVV P                  V P                  V P                  V P
                  4       R# )zVerify the included signature with regard to the given app and client
params.

:param app_param: SHA256 hash of the app ID used for the request.
:param client_param: SHA256 hash of the ClientData used for the request.
N)r   Zverify_signaturer-   r,   r.   r/   )r$   rC   rD   r%   r   verifyZRegistrationData.verifym   s6     	++OOOONN	
r   c               r   )r   r   r<   r;   r+   r   r   r    r   r!   r3   ~   s     ) )C )$4 )r   c                $    V ! \        V4      4      # )zParse a RegistrationData from a websafe base64 encoded string.

:param data: Websafe base64 encoded string.
:return: The decoded and parsed RegistrationData.
r   Zclsr      &&r   from_b64ZRegistrationData.from_b64}        >$'((r   )r.   r-   r,   r/   r   r   r   r   r   Z__annotations__r&   Zpropertyr@   rF   ZclassmethodrK   r   Z__classcell__r9      @r   r+   r+   C   sY     ' '( $ $
  ) )r   r+   c                  s   a  ] tR t^t$ RtR]R&   R]R&   R]R&   R V 3R llt]R	 R
 l4       tR R lt	]
R R l4       tRtV ;t# )SignatureDatazBinary response data for a CTAP1 authentication.

:param _: The binary contents of the response data.
:ivar user_presence: User presence byte.
:ivar counter: Signature counter.
:ivar signature: Cryptographic signature.
r   user_presencecounterr   r/   c               r0   r1   r   r   r    r   r!   SignatureData.__annotate__   s     ' '% 'r   c                	s   < \         SV `  4        \        V 4      pVP                  R 4      V n        VP                  R4      V n        VP                  4       V n        R# )r4   z>IN)r5   r&   r	   r6   rQ   rR   r7   r/   )r$   r2   r8   r9   s   && r   r&   ZSignatureData.__init__   sF    D!#]]3/}}T*r   c               r0   r:   r   r   r    r   r!   rS      r=   r   c                r>   )z8str: Websafe base64 encoded string of the SignatureData.r?   r(   r)   r   r@   ZSignatureData.b64   rA   r   c               s(    V ^8  d   QhRRRRRRRR/# )r   rC   r   rD   r,   r;   rE   r   r   r    r   r!   rS      s)     	? 	? 	?U 	? 	?RV 	?r   c                s    WR,          ,           V,           p\         P                  ! V4      P                  W@P                  4       R# )a=  Verify the included signature with regard to the given app and client
params, using the given public key.

:param app_param: SHA256 hash of the app ID used for the request.
:param client_param: SHA256 hash of the ClientData used for the request.
:param public_key: Binary representation of the credential public key.
:Ni   NN)r   Z
from_ctap1rF   r/   )r$   rC   rD   r,   Zms   &&&& r   rF   ZSignatureData.verify   s2     R </$++A~~>r   c               r   )r   r   r<   r;   rP   r   r   r    r   r!   rS      s     ) )C )M )r   c                rG   )zParse a SignatureData from a websafe base64 encoded string.

:param data: Websafe base64 encoded string.
:return: The decoded and parsed SignatureData.
rH   rI   rJ   r   rK   ZSignatureData.from_b64   rL   r   )rR   r/   rQ   rM   rN   rO   r   rP   rP      sR     L' ' $ $	? ) )r   rP   c                  s~    ] tR t^tRt] ! R R]4      4       tR R ltRR R llt	R R	 lt
R
 R ltRR R lltRtR# )Ctap1zdImplementation of the CTAP1 specification.

:param device: A CtapHidDevice handle supporting CTAP1.
c                  s"    ] tR t^t^t^t^tRtR# )	Ctap1.INSr   N)r   r   r   r   REGISTERAUTHENTICATEVERSIONr   r   r   r   INSrU      s    r   rY   c               r0   )r   devicer   r   r   r    r   r!   Ctap1.__annotate__   s      z r   c                	s    Wn         R # r"   rZ   )r$   rZ   rJ   r   r&   ZCtap1.__init__   s    r   c               s0    V ^8  d   QhRRRRRRRRRRRR/# )	r   clar   insp1p2r   r   r;   r   r   r    r   r!   r[      s<      !$.1;>JO	r   c                sH   \         P                  ! RWW4^ \        V4      4      V,           R,           pV P                  P	                  \
        P                  V4      p\         P                  ! RVRR 4      ^ ,          pVRR pV\        P                  8w  d   \        W4      hV# )a  Packs and sends an APDU for use in CTAP1 commands.
This is a low-level method mainly used internally. Avoid calling it
directly if possible, and use the get_version, register, and
authenticate methods if possible instead.

:param cla: The CLA parameter of the request.
:param ins: The INS parameter of the request.
:param p1: The P1 parameter of the request.
:param p2: The P2 parameter of the request.
:param data: The body of the request.
:return: The response APDU data of a successful request.
:raise: ApduError
z>BBBBBHs     z>HNi)structpackr'   rZ   Zcallr   ZMSGr6   r   r   r   )	r$   r]   r^   r_   r`   r   ZapduresponseZstatuss	   &&&&&&   r   	send_apduZCtap1.send_apdu   s      {{9c3t9ELwV;;##GKK6tXbc]3A6}TWWF))r   c               r0   r:   r   r   r    r   r!   r[      s     > >S >r   c                sr    V P                  \        P                  P                  R7      P	                  4       # )z~Get the U2F version implemented by the authenticator.
The only version specified is "U2F_V2".

:return: A U2F version string.
)r^   )rd   rT   rY   rX   Zdecoder(   r)   r   get_versionZCtap1.get_version   s(     ~~%))"3"3~4;;==r   c               rB   )r   rD   r   rC   r;   r+   r   r   r    r   r!   r[      s"     	* 	*U 	*u 	*AQ 	*r   c                s~    W,           pV P                  \        P                  P                  VR7      p\	        V4      # )zRegister a new U2F credential.

:param client_param: SHA256 hash of the ClientData used for the request.
:param app_param: SHA256 hash of the app ID used for the request.
:return: The registration response from the authenticator.
)r^   r   )rd   rT   rY   rV   r+   )r$   rD   rC   r   rc   s   &&&  r   registerZCtap1.register   s3     '>>eii&8&8t>D))r   c          
     s,    V ^8  d   QhRRRRRRRRRR/# )	r   rD   r   rC   r-   
check_onlyZboolr;   rP   r   r   r    r   r!   r[      s<     ' '' ' 	'
 ' 
'r   c                s    W,           \         P                  ! R\        V4      4      ,           V,           pV'       d   ^M^pV P                  \        P
                  P                  WeR7      p\        V4      # )a  Authenticate a previously registered credential.

:param client_param: SHA256 hash of the ClientData used for the request.
:param app_param: SHA256 hash of the app ID used for the request.
:param key_handle: The binary key handle of the credential.
:param check_only: True to send a "check-only" request, which is used to
    determine if a key handle is known.
:return: The authentication response from the authenticator.
z>B)r^   r_   r   )ra   rb   r'   rd   rT   rY   rW   rP   )r$   rD   rC   r-   rg   r   r_   rc   s   &&&&&   r   authenticateZCtap1.authenticate   sZ    " $v{{4Z'IIJV 	  TT>>eii&<&<>OX&&r   r\   N)r    r    r    r    r   )F)r   r   r   r   r   r   r   rY   r&   rd   re   rf   rh   r   r   r   r   rT   rT      s@    
 g  
2>	*' 'r   rT   )Z
__future__r   ra   Zdataclassesr   Zenumr   r   Zattestationr   Zcoser   Zctapr   Zhidr   Zutilsr	   r
   r   r   r   Z	Exceptionr   r   r+   rP   rT   r   r   r   <module>ri      s   8 #  !   +    H H 7  Q	 Q" @)u @) @)F ,)E ,) ,)^P' P'r   