+
    :i  c                   sH   ^ RI t ^ RIt^ RIt^ RIt^ RIHt ^ RIt^ RIHtH	t	H
t
HtHt ^RIHtHtHt ] P"                  ! ]4      t]P(                  ! R]P*                  4      tR R ltR R	 ltR
 R lt]! ].R]P4                  9  R7      ]P6                  ]P8                  ! RRRRR7      ]P8                  ! RR]! ]4      RRR7      ]P8                  ! RRRR7      ]P:                  ! RR!R7      ]P8                  ! RRRRR7      R  4       4       4       4       4       4       4       tR# )"i    N)a2b_hex)AIDSW	ApduErrorSmartCardConnectionSmartCardProtocol)CliFail
EnumChoiceclick_commandz^(?P<cla>[0-9a-f]{2})?(?P<ins>[0-9a-f]{2})(?P<params>[0-9a-f]{4})?(?::(?P<body>(?:[0-9a-f]{2})+))?(?:/(?P<le>[0-9a-f]{2}))?(?P<check>=(?P<sw>[0-9a-f]{4})?)?$c                s0    V ^8  d   QhR\         R\        /# )   datareturn)bytesstrZformat   "4/usr/lib/python3.14/site-packages/ykman/_cli/apdu.py__annotate__r   <   s     . .u . .    c                 s2    R P                  R V  4       4      # ) c              3   (   "   T F  qR  x  K
  	  R# 5i02XN ).0Zd   & r   	<genexpr>Z_hex.<locals>.<genexpr>=   s     -1gJ   )join)r
   s   &r   _hexr   <   s    88----r   c                s    V ^8  d   QhR\         R\        \        \        \        \        \        \        \        3,          \        R,          3,          /# )r	   r
   r   N)r   Ztupleintr   r   r   r   r   r   @   s<     , ,
,
5c3UC/0#*<=,r   c                 sj   \         P                  V 4      pV'       g   \        R V ,           4      h\        VP	                  R4      ;'       g    R^4      p\        VP	                  R4      ^4      p\        VP	                  R4      ;'       g    R^4      p\        VP	                  R4      ;'       g    R4      p\        VP	                  R4      ;'       g    R^4      pVP	                  R	4      '       d'   \        VP	                  R
4      ;'       g    R^4      pMRpV^,	          V^,          rW#WWV3V3# )zInvalid APDU format: claZ00insparamsZ0000body lecheckswZ9000N)APDU_PATTERNZmatchZ
ValueErrorr   Zgroupr    )
r
   Zmr   r    r!   r"   r$   r&   Zp1Zp2s
   &         r   _parse_apdur(   @   s     	4 A04788
aggen$$b
)C
aggenb
!C",,fb1F1776?((b)D	QWWT]""dB	'BwwwQWWT]44fb9q[&4-bd'++r   c                s@    V ^8  d   QhR\         R\        R\        RR/# )r	   respr&   	no_prettyr   N)r   r   Zboolr   r   r   r   r   S   s(      % S T d r   c                 s   \         P                  ! R VR R2V '       d   RMR,           4       V'       d5   \         P                  ! V P                  4       P                  4       4       R# \	        ^ \        V 4      ^4       Ff  pWV^,            p\         P                  ! RP                  R V 4       4      P                  ^24      RP                  R V 4       4      ,           4       Kh  	  R# )	z	RECV (SW=04X)Z:r#   r   c              3   r   r   r   r   Zcr   r   r   "_print_response.<locals>.<genexpr>[   s     3Uc7Ur   c              3   sr   "   T F-  p^Tu;8  d   ^8  d   M M\        V4      M
\        ^4      x  K/  	  R# 5i)i   N)Zchrr-   r   r   r   r.   ]   s'     N1BLSL#a&c#h>s   57N)clickechoZhexZupperZrangeZlenr   Zljust)r)   r&   r*   ZiZchunks   &&&  r   _print_responser1   S   s    	JJ2c(!$t<=

488:##%&q#d)R(AQV$EJJ3U3399"=''NNNO )r   z--full-help)ZconnectionsZhiddenz-xz--no-prettyTz'print only the hex output of a response)Zis_flaghelpz-az--appFzselect application)ZtypeZrequiredr2   z--shortzforce usage of short APDUsapdu)Znargsz-sz--send-apduzprovide full APDUs)Zmultipler2   c           	     s   V'       g"   V'       g   V'       g   V P                  R4       V'       g	   V'       d   V'       d   V P                  R4       R V 4       pV P                  R,          pVP                  \        4      ;_uu_ 4       pRp	V'       d|   V Fs  pV	'       g   \        P
                  ! 4        MRp	\        V4      p\        P
                  ! R\        V4      ,           4       VP                  V4      w  r\        WV4       Ku  	  EMV P                  R,          p\        V4      pV P                  P                  R	4      pV'       d
   V! V4      pMR
pVP                  VP                  VR7       V'       dU   Rp	\        P
                  ! R\        V4      ,           4       VP                  V4      p
\        V
\        P                   V4       V'       d(   \        P
                  ! R4       VP#                  V4       V EF   w  ppV	'       g   \        P
                  ! 4        MRp	VR,          V^,          V^,          ppp\        \$        P&                  ! R.VO5!  4      pV'       d   VR\        V4      ,           ,          pV'       d   VRVR R2,          p\        P
                  ! RV,           4        VP(                  ! V!  p
\        P                   p\        WV4       Vf   K  VV8w  g   K  \1        RVR R24      h	  R
R
R
4       R
#   \*         d#   pTP,                  p
TP.                  p R
p?L_R
p?ii ; i  + '       g   i     R
# ; i)a  
Execute arbitrary APDUs.
Provide APDUs as a hex encoded, space-separated list using the following syntax:
[CLA]INS[P1P2][:DATA][/LE][=EXPECTED_SW]

If not provided CLA, P1 and P2 are all set to zero.
Setting EXPECTED_SW will cause the command to check the response SW and fail if it
differs. "=" can be used as shorthand for "=9000" (SW=OK).

As an alternative, you can provide full APDUs using the -s/--send-apdu option. You
cannot mix -a and positional APDUs with --send-apdu.

Examples:


  Select the OATH application, send a LIST instruction (0xA1), and make sure we get
  sw=9000 (these are equivalent):
  $ ykman apdu a40400:a000000527210101=9000 a1=9000
    or
  $ ykman apdu -a oath a1=


  Factory reset the OATH application:
  $ ykman apdu -a oath 04dead
    or
  $ ykman apdu a40400:a000000527210101 04dead
    or (using full-apdu mode)
  $ ykman apdu -s 00a4040008a000000527210101 -s 0004dead


  Get 8 random bytes from the OpenPGP application:
  $ ykman apdu -a openpgp 84/08=
zNo commands provided.z/Cannot mix positional APDUs and -s/--send-apdu.c              3   s8   "   T F  p\        V4      x  K  	  R # 5i)N)r(   )r   r
   r   r   r   Zapdu.<locals>.<genexpr>   s     044[4s   ZdeviceTFzSEND: infoZscpN)Zforce_shortzSELECT AID: zINITIALIZE SCP:Ni   Nz>BBBBz -- z (LE=r   r,   z"Aborted due to error (expected SW=r+   z).)ZfailZobjZopen_connectionr   r/   r0   r    r   Zsend_and_receiver1   r   ZgetZ	configureZversionZselectr   ZOKZinit_scpstructZpack	send_apdur   r
   r&   r   )Zctxr*   ZappZshortr3   r6   ZapdusZdevZconnZis_firstr)   r&   r4   ZprotocolZscp_resolver!   r%   Zheaderr"   r$   ZreqZes   &&&&&&                r   r3   r3   a   s|   b T#()tBC040E
''(
C			0	1	1T!JJL$Ht}

8d4j01006)4 " 776?D(.H''++e,K$T* t||? 

>DI56s+beeY7

+,!!&)$eJJL$H#'8T!Wd1gb6;;w8896DJ..CU2c(!,,C

8c>*#--t4DB  )4$u!$FuSkQS"TUU+  %I 
2	1f ! 66DBg 
2	1	1sW   C6MAMB4M+M  L M2M;MM	"L?	:M?M	MM	i)ZloggingZrer5   ZsysZbinasciir    r/   Zyubikit.core.smartcardr   r   r   r   r   Zutilr   r   r   Z	getLoggerZ__name__ZloggerZcompileZ
IGNORECASEr'   r   r(   r1   ZargvZpass_contextZoptionZargumentr3   r   r   r   <module>r7      s)  8  	  
    5 4			8	$ zz	 MM.,& /0chh9VW-,U 	C	 i,HIb!dMD7KLcV M " J  XcVr   