+
    :i1  c                   sf  a  R" t;0 t ^ RIt^ RIt^ RIt^ RIHt ^ RIHtHt ^ RIH	t	H
t
HtHtHt ^ RIHt ^ RIHtHtHtHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHtHt ^ RIHt ^RI H!t!H"t"H#t# ^RI$H%t& ^RI$H't( ^RI)H*t+ ]PX                  ! ]-4      t.]/3R lt0]0! R]4      R 4       t1]0! R4      R 4       t%]0! R4      R 4       t']2],          ]2],          ,          t3] ^ k ]]1]]']]%/t4] ^k R R lt5 ! R R4      t6 ! R R]#4      t7]4Pq                  4       R3R R llt9]4Pq                  4       3R  R! llt:R# )#i    N)Counter)sleeptime)CallableHashableIterableMapping	TypeAlias)EstablishContextException)PID	TRANSPORTYUBIKEY
Connection)FidoConnection)OtpConnection)SmartCardConnection)USB_INTERFACE
DeviceInfo)	read_info)REINSERT_STATUSCancelledExceptionYkmanDevice)list_ctap_devices)list_otp_devices)list_devicesc                 s    a aa . oVV V3R  lpV# )c                 s   <a  VV VV3R  lpV# )c                  s   <  S! 4       #   S  d1    S'       g'   \         P                  S4       SP                  R 4       h i ; i)T)loggerwarningappend)e_typefmessagewarneds   1/usr/lib/python3.14/site-packages/ykman/device.pyinnerZ(_warn_once.<locals>.outer.<locals>.inner?   s<    s
 NN7+MM$'	s   
 A(A )r   r!   r   r   r   s   f r    outerZ_warn_once.<locals>.outer>   s    	 	     r"   )r   r   r#   r   s   ff @r    
_warn_oncer%   ;   s    F
 Lr$   zCPC/SC not available. Smart card (CCID) protocols will not function.c                     \        4       # )zList CCID devices.)_list_ccid_devicesr"   r$   r    list_ccid_devicesr(   M   s     r$   z@No CTAP HID backend available. FIDO protocols will not function.c                 r&   )zList CTAP devices.)_list_ctap_devicesr"   r$   r    r   r   V   s     r$   z>No OTP HID backend available. OTP protocols will not function.c                 r&   )zList OTP devices.)_list_otp_devicesr"   r$   r    r   r   \   s     r$   c                sh    V ^8  d   QhR\         \        \        \        3,          \        3,          /# )   return)tupler   r	   ZintZformat   "r    __annotate__r0   l   s&     - -eGCH-s23 -r$   c                 sB   \        4       p / p\        P                  4        FV  p V! 4       pVP                  \        R V 4       4      4       T P                  V Uu0 uF  qDP                  kK  	  up4       KX  	  \        P                  R8X  d   \        \        P                  P                  P                  4       4      '       gj   ^RIHp \        4       pV! 4        F=  w  rxWq9  g   K   V\%        V4      ;;,          ^,          uu&   V P'                  V4       K?  	  VP                  V4       V\+        \-        V 4      4      3#   \         d    \        P                  RRR7       . p ELAi ; iu upi   \(         d    \        P                  RTR 24        K  i ; i)	zScan USB for attached YubiKeys, without opening any connections.

:return: A dict mapping PID to device count, and a state object which can be used to
    detect changes in attached devices.
zDevice listing errorTZexc_infoc              3   sX   "   T F   qP                   f   K  VP                   x  K"  	  R # 5iN)pid).0ds   & r    	<genexpr>Zscan_devices.<locals>.<genexpr>z   s     GTUUeaeeTs   **Zwin32)
list_pathsz$Unsupported Yubico device with PID: Z02x)set_CONNECTION_LIST_MAPPINGvalues	Exceptionr   debugZupdater    fingerprintsysZplatformboolctypesZwindllZshell32ZIsUserAnAdminZhid.windowsr7   r	   add
ValueErrorZhashr-   )	ZfingerprintsZmergedZ	list_devsdevsr5   r7   Zcounterr3   Zpaths	            r    scan_devicesrD   l   sO    5LF-446		;D 	gGTGGHD9Dq]]D9: 7 ||wtFMM,A,A,O,O,Q'R'R+ '	#IC SCH%*% $$T*	 & 	g4l+,,,#  	LL/$L?D	 : " SLL#GCy!QRSs)   EE1
,/E6$E.-E.6$FFc                   sH   a  ] tR t^t o R tR tR	R ltR tR tR t	Rt
V tR# )
	_PidGroupc                s    Wn         / V n        / V n        / V n        \	        4       V n        \        4       V n        \        4       V n	        R # r2   )
_pid_infos	_resolved_unresolvedr    	_devcountr8   _fingerprintsr   _ctime)selfr3      &&r    __init__Z_PidGroup.__init__   s9    	24KMCE3:9,/Efr$   c                s    VP                   VP                  VP                  \        VP                  4      VP
                  P                  R 4      VP                  VP                  VP                  3# )F)
serialversionZform_factorZstrZsupported_capabilitiesZconfigZ	get_bytesZ	is_lockedZis_fipsZis_sky)rM   inforN   r    _keyZ_PidGroup._key   sX    KKLL++,KK!!%(NNLLKK	
 		
r$   c                sp   \         P                  R V RV 24       VP                  pV P                  P	                  VP
                  4       V P                  V;;,          ^,          uu&   V'       g<   \        V P                  4      \        V P                  P                  4       4      8  d    VP                  V4      ;_uu_ 4       p\        WbP                  4      pRRR4       V P                  X4      pWpP                  V&   W P                  P!                  V/ 4      V&   \         P                  RVP"                   24       R# V P(                  P!                  V. 4      P+                  V4       R#   + '       g   i     L; i  \$         d#    T'       g   \         P'                  RRR7        Lli ; i)zAdd device for z: NResolved device Failed opening deviceTr1   )r   r<   usb_interfacerK   rA   r=   rJ   lenrH   Zmaxr:   open_connectionr   r3   rS   rG   
setdefaultrP   r;   r   rI   r   )	rM   	conn_typedevZforce_resolvesilentifaceconnrR   keys	   &&&&&    r    rA   Z_PidGroup.add   sC   ykC59:''s/u"C/#dnn6K6K6M2NN
K((33t$T773D 4iio#'C <?))#r259/}=> 	##E2.55c: 43  KNN#:TNJKs1   0F 	E5A'F 5F	 F F5F54F5c                s4    VP                   V P                  9   # r2   )rV   rJ   )rM   rZ   rN   r    supports_connectionZ_PidGroup.supports_connection   s    &&$..88r$   c                s   VP                   pV P                  V,          P                  V4      pV'       d   VP                  V4      # V P                  P                  V. 4      p. p V'       Ed=   VP                  4       p VP                  V4      p\        WP                  4      p	V P                  V	4      p
WP                  9   d[   WpP                  P                  V
/ 4      V&   \        P                  R V	P                   24       W8X  d   VVP                  V4       # MwV P                  P                   \"        P$                  8X  dO   V'       gG   WpP                  P                  V/ 4      V&   \        P                  R4       VVP                  V4       # VP'                  4        EKE   VP                  V4       V P.                  V,          \1        V P                  4      8  d   \        P                  RV: 24       \2        V,          ! 4        FO  pV P                  VP                  8X  g   K   VP4                  V P6                  9  g   K=  V P9                  W'R4       KQ  	  V P                  V,          P                  V4      pV'       d   VP                  V4      # \;        4       V P<                  ^,           8  d2   \        P                  R4       \?        R4       V PA                  W4      # \C        R4      h  \(         d.    \        P+                  RRR7       TP-                  T4        EK  i ; i  TP                  T4       i ; i)	rT   z'Resolved last NEO device without serialrU   Tr1   zChecking for more devices over zDevice not found, retry in 1sg      ?zFailed to connect to the device)"rV   rH   ZgetrX   rI   Zpopr   r3   rS   rG   rY   r   r<   rP   extendrF   Zyubikey_typer   ZNEOZcloser;   r   r   rJ   rW   r9   r=   rK   rA   r   rL   r   connectrB   )rM   r_   rZ   r]   ZresolvedrC   Zfailedr[   r^   rR   Zdev_keys   &&&        r    rb   Z_PidGroup.connect   s   ''>>#&**51++I66##E2.	 $hhj'..y9D$T773D"iioG++-HK11'2>uE'7}%EF">#' KK *//7;;>tDG11#r:5A%NO# KK JJL ( KK>>% 3t{{#33LL:5)DE/	:<99'COO4CUCU,UHHYT2 = ~~c*..u5H//	:: 6DKK!O#LL89#J<<//:;;/ ! 'NN#:TNJMM#&&' KKsI   'L9 0L9 BK> !1K> 4K> K> )L9 >3L61L9 5L66L9 9Mc           
     s   . pV P                   P                  4        Fk  w  r#\        \        V P                  V,          P                  4       4      4      pVP                  \        WVP                  VP                  V4      V34       Km  	  V# r2   )
rG   ZitemsZnextZiterrH   r:   r   _UsbCompositeDevicer=   r3   )rM   Zresultsr_   rR   r[   s   &    r    get_devicesZ_PidGroup.get_devices   sp    **,ICtDNN3/6689:CNN$T$OQUV -
 r$   )rL   rJ   rK   rG   rF   rH   rI   N)FF)__name__
__module____qualname____firstlineno__rO   rS   rA   r`   rb   rd   __static_attributes____classdictcell__)__classdict__   @r    rE   rE      s)     

;&91<f r$   rE   c                   sD   a a ] tR t^t oV 3R ltR tR tR tRtVt	V ;t
# )rc   c                sh   < \         SV `  \        P                  W44       Wn        W n        WPn        R # r2   )ZsuperrO   r
   ZUSB_grouprS   _info)rM   groupr_   r=   r3   rR   	__class__s   &&&&&&r    rO   Z_UsbCompositeDevice.__init__   s%    9	
r$   c                s8    V P                   P                  V4      # r2   )rm   r`   rM   connection_typerN   r    r`   Z'_UsbCompositeDevice.supports_connection   s    {{..??r$   c                s    V P                  V4      '       g   \        R 4      hV P                  P                  V P                  V4      # )zUnsupported Connection type)r`   rB   rm   rb   rS   rq   rN   r    rX   Z#_UsbCompositeDevice.open_connection   s:    ''88:;;{{""499o>>r$   c                s  a a \        4       w  r4R p\        VP                  4       4      pV 3R lo\        P	                  RS P
                  P                   24       V! \        P                  4       VP                  R4      '       Eg.   \        4       w  rxW8X  d   K,  Tp\        RR7      p	V'       g   Ws8X  d   KJ  V\        VP                  4       4      ^,           8w  gA   \        ;QJ d    V3R lV	 4       F  '       g   K   RM	  R M! V3R lV	 4       4      '       d   \        R4      hRpV! \        P                  4       K  V\        VP                  4       4      8w  d   \        R4      hV	 F?  w  rS! V4      '       g   K  V
P                  S n        V
P                  S n        VS n         R# 	  EKE  \!        4       h)	Fc                 s   < SP                   P                  V P                  8H  ;'       d$    SP                   P                  V P                  8H  # r2   )rn   rP   rQ   )rR   rM   s   &r    is_matchZ2_UsbCompositeDevice._do_reinsert.<locals>.is_match	  s9    

!!T[[0WWTZZ5G5G4<<5Wr$   z%Waiting for removal of device serial=g      ?Tr\   c              3   s8   <"   T F  w  rS! V4      x  K  	  R # 5ir2   r"   )r4   Z_rR   rs   s   &  r    r6   Z3_UsbCompositeDevice._do_reinsert.<locals>.<genexpr>  s      ?26wqHTNN$s   z(A different YubiKey was inserted/removedN)rD   Zsumr:   r   r<   rn   rP   r   ZREMOVEZwait_list_all_devicesZanyrB   ZREINSERTrm   rS   r   )rM   Zreinsert_cbZeventZpidsZstateZremovedZn_devsZnew_pidsZ	new_staterC   r[   rR   rs   s   f&&         @r    _do_reinsertZ _UsbCompositeDevice._do_reinsert  sZ   "nT[[]#	
 	<TZZ=N=N<OPQO**+**S//"..H!E$D1D#S!23a7733 ?26?333 ?26? < < %%OPPO445 S!233$%OPP!%IC~~&)jj$'HH	%)
 "& !""r$   )rm   rn   rS   )re   rf   rg   rh   rO   r`   rX   rv   ri   rj   Z__classcell__)rp   rk   s   @@r    rc   rc      s     @?,# ,#r$   rc   Fc          	      s    V ^8  d   QhR\         \        ,          R\        R\        \        \
        \        3,          ,          /# )r+   connection_typesr\   r,   )r   _T_CONNECTIONr?   listr-   r   r   r.   r/   r    r0   r0   3  s:      }- 
%Z'
()r$   c                 s   / pV  F  p\          F  p\        W44      '       g   K  Tp M	  \        R 4      h \         V,          ! 4        FF  pVP                  VP                  \        VP                  4      4      pVP                  VVVR7       KH  	  K  	  . pVP                  4        F"  pVP                  VP                  4       4       K$  	  V#   \         d%    T'       g   \        P                  R4        K   K  i ; i)zInvalid connection typert   z%Unable to list devices for connection)r9   Z
issubclassrB   rY   r3   rE   rA   r;   r   Z	exceptionr:   ra   rd   )rw   r\   Zgroupsrr   Z	base_typer[   ro   Zdevicess   &&      r    ru   ru   3  s     $&F+1I/55"+ 2
 677	J/@B))#''9SWW3EF		#!   C ,& Gu((*+ !N  	J  !HI 	Js   ACC?#C?>C?c                s~    V ^8  d   QhR\         \        ,          R\        \        \        \
        3,          ,          /# )r+   rw   r,   )r   rx   ry   r-   r   r   r.   r/   r    r0   r0   Q  s0     / /}-/	%Z'
()/r$   c                s    \        V 4      # )zConnect to all attached YubiKeys and read device info from them.

:param connection_types: An iterable of YubiKey connection types.
:return: A list of (device, info) tuples for each connected device.
)ru   )rw   s   &r    list_all_devicesrz   Q  s     -..r$   c                s    V ^8  d   Qh/ ^ \         9   d
   \        ;R&   ^\         9   d3   \        \        \        . \
        \        ,          3,          3,          ;R&   # )r+   rx   r9   )__conditional_annotations__r   Zdictrx   r   r   r   r.   r/   r    r0   r0      sL    L C By BM R $}hr8K;P7P.QQR S r$   )<r{   r@   Zloggingr>   Zcollectionsr    r   r   Ztypingr   r   r   r   r   Zsmartcard.pcsc.PCSCExceptionsr   Zyubikit.corer	   r
   r   r   Zyubikit.core.fidor   Zyubikit.core.otpr   Zyubikit.core.smartcardr   Zyubikit.managementr   r   Zyubikit.supportr   Zbaser   r   r   Zhidr   r)   r   r*   Zpcscr   r'   Z	getLoggerre   r   r;   r%   r(   Ztyperx   r9   rD   rE   rc   Zkeysru   rz   r0   )r{   rl   r    <module>r|      sI  8   
   C C C < < , * 6 & B B 5			8	$  ) $ I 	 
 NO  P 
 LM N
  
+d>.BB B *#%V  ->f fR<#+ <#@ 1I0M0M0O> 1I0M0M0O/ /r$   