+
    :i  c                  s  a  0 t $ ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RI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Ht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I#H$t$ ^ RI%H&t& ^ RI'H(t(H)t)H*t* ^ RI+H,t, ^ RI-H.t.H/t/H0t0H1t1 ^RI2H3t3H4t4H5t5H6t6H7t7H8t8H9t9H:t:H;t; ^RI<H=t=H>t>H?t?H@t@HAtAHBtB ]'       d   ^ RICHDtD ]P                  ! ]F4      tG]!P                  ]P                  ,          ] P                  ,          ]"P                  ,          tLR]MR&   ]!P                  ]P                  ,          ] P                  ,          ]"P                  ,          tRR]MR&   ] ! R R]S]4      4       tT] ! R R]4      4       tU] ! R R]4      4       tVR tW^tX^tY] ! R R]4      4       tZ] ! R  R!]4      4       t[] ! R" R#]4      4       t\] ! R$ R%]4      4       t]RHt^^t_^t`^ ta^$tb^,tc^Gtd^te^tf^tg^th^ti^tj^tk^tl^tm^tn^to^tp^tq^tr^ts^tt^tu^Stv^\tw^ptx^qty^|tz^t{^t|^t}^t~^t^t^t^t^t^t^t^t^t^ t^t^ t^t^t^t^tR& tR' t] ! R( R)4      4       t] ! R* R+4      4       t] ! R, R-4      4       t] ! R. R/4      4       tRIR0 ltR1 R2 ltR3tR4tR5tRJt] ! R6 R74      4       t]! R8R97       ! R: R;4      4       tR< tR= tRKR> R? lltRLR@ RA lltRB t]
! RC4      tRD RE lt ! RF RG4      tR# )M    )annotationsN)	b64decode)astuple	dataclass)date)EnumIntEnumunique)TYPE_CHECKING	TypeAliasoverload)x509)default_backend)hashes)eced25519rsax25519)AsymmetricPadding)	Prehashed)Cipher
algorithmsmodes)bytes_eq)EncodingNoEncryptionPrivateFormatPublicFormat)	BadResponseErrorInvalidPinErrorNotSupportedErrorTlvVersion_override_version	bytes2int	int2bytesrequire_version)AIDSW	ApduErrorScpKeyParamsSmartCardConnectionSmartCardProtocol)PublicKeyTypesr
   	PublicKey
PrivateKeyc                  s    ] tR t^ctRtRtRtR# )	ALGORITHMr   r    N)__name__
__module____qualname____firstlineno__ECRSA__static_attributes__r0       0/usr/lib/python3.14/site-packages/yubikit/piv.pyr/   r/   c   s    	B
Cr8   r/   c                  s~    ] tR t^it^t^t^t^t^t^t	^t
^tR t]R R l4       t]R R l4       t]R R l4       tRtR	# )
KEY_TYPEc                	    V P                   # Nnameself   &r9   __str__ZKEY_TYPE.__str__t   s    yyr8   c                   V ^8  d   QhRR/# )   returnr/   r0   Zformat   "r9   __annotate__KEY_TYPE.__annotate__x   s     N N9 Nr8   c                	s    V P                   P                  R 4      '       d   \        P                  # \        P                  # )r6   )r>   Z
startswithr/   r6   r5   r?   rA   r9   	algorithmZKEY_TYPE.algorithmw   s)     $		 4 4U ; ;y}}MMr8   c               rC   rD   rE   intr0   rF   rG   r9   rH   rI   |   s     ' ' 'r8   c                	s    V \         P                  \         P                  39   d   R # \        P                  ! RV P
                  4      pV'       d   \        VP                  4       4      # \        R4      h)i   z\d+$z
No bit_len)	r:   ED25519X25519reZsearchr>   rL   Zgroup
ValueError)r@   Zmatch   & r9   bit_lenZKEY_TYPE.bit_len{   sO    H$$hoo66		'499-u{{}%%&&r8   c                    V ^8  d   QhRRRR/# )rD   keyr,   rE   r:   r0   rF   rG   r9   rH   rI      s     H H. HX Hr8   c                	s   \        V\        P                  4      '       d    \        V R VP                  ,          4      # \        V\        P                  4      '       dK   VP                  P                  pVR8X  d   V P                  # VR8X  d   V P                  # \        RV 24      h\        V\        P                  4      '       d   V P                  # \        V\         P"                  4      '       d   V P$                  # \        R\'        V4      P(                   24      h  \
         d    \        RTP                  ,          4      hi ; i)zRSA%dzUnsupported RSA key size: %dZ	secp256r1Z	secp384r1zUnsupported EC curve: zUnsupported key type: )
isinstancer   RSAPublicKeygetattrZkey_sizeAttributeErrorrP   r   EllipticCurvePublicKeycurver>   ECCP256ECCP384r   Ed25519PublicKeyrM   r   X25519PublicKeyrN   Ztyper1   )clsrT   Z
curve_name   && r9   from_public_keyZKEY_TYPE.from_public_key   s
   c3++,,PsGcll$:;; R6677J[({{"{*{{"5j\BCCW5566;;V3344::1$s)2D2D1EFGG " P !?#,,!NOOPs   D" "(E
r0   N)r1   r2   r3   r4   RSA1024ZRSA2048RSA3072RSA4096r[   r\   rM   rN   rB   propertyrJ   rR   classmethodra   r7   r0   r8   r9   r:   r:   i   so    GGGGGGGF N N ' ' H Hr8   r:   c                  sR    ] tR t^t^t^t^
t^t]R R l4       t	]R R l4       t
RtR# )MANAGEMENT_KEY_TYPEc               rC   rK   r0   rF   rG   r9   rH    MANAGEMENT_KEY_TYPE.__annotate__   s     ' ' 'r8   c                	sn    V P                   R 8X  d   ^# \        V P                   R,          4      ^,          # )TDES:   NN)r>   rL   r?   rA   r9   key_lenZMANAGEMENT_KEY_TYPE.key_len   s)    99499R=!Q&&r8   c               rC   rK   r0   rF   rG   r9   rH   rh      s      s r8   c                	s,    V P                   R 8X  d   ^# ^# )ri   r=   r?   rA   r9   challenge_lenZ!MANAGEMENT_KEY_TYPE.challenge_len   s    99r8   r0   N)r1   r2   r3   r4   ri   ZAES128ZAES192ZAES256re   rk   rl   r7   r0   r8   r9   rg   rg      s<    DFFF' '  r8   rg   c                s    V \         P                  8X  d    ^ RIHp V! V4      # \
        P                  ! V4      #   \         d    \
        P                  p L;i ; i)r    )	TripleDES)rg   ri   Z/cryptography.hazmat.decrepit.ciphers.algorithmsrm   ZImportErrorr   ZAES)key_typemanagement_keyrm   r`   r9   _parse_management_keyrp      sQ    &+++	-Q ((~~n--	  	-",,I	-s   ; AAc                  s    ] tR t^t^t^t^t^t^t^t	^t
^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^tR R ltRtR# )SLOTc               rC   )rD   rE   strr0   rF   rG   r9   rH   ZSLOT.__annotate__   s     0 0 0r8   c                	s:    \        V 4      R  RV P                   R2# )Z02Xz ())rL   r>   r?   rA   r9   rB   ZSLOT.__str__   s    d)C499+Q//r8   r0   N)r1   r2   r3   r4   AUTHENTICATION	SIGNATUREKEY_MANAGEMENT	CARD_AUTHRETIRED1RETIRED2RETIRED3RETIRED4RETIRED5RETIRED6RETIRED7RETIRED8RETIRED9	RETIRED10	RETIRED11	RETIRED12	RETIRED13	RETIRED14	RETIRED15	RETIRED16	RETIRED17	RETIRED18	RETIRED19	RETIRED20ATTESTATIONrB   r7   r0   r8   r9   rq   rq      s    NINIHHHHHHHHHIIIIIIIIIIIK0 0r8   rq   c                  s    ] tR t^tRtRtRtRtRtRt	Rt
RtR	tR
t^~tRtRtRtRtRtRtRtRtRtRtRtRtRtRtRtRtRtRt Rt!Rt"Rt#R t$R!t%]&R" R# l4       t'R$t(R%# )&	OBJECT_IDi_ i_ i_ i_ i_ i_ i	_ i
_ i_ i_ i_ i!_ i_ i_ i_ i_ i_ i_ i_ i_ i_ i_ i_ i_ i_ i_ i_ i_ i_ i_ i_ i _ i_ c               rS   )rD   slotrq   rE   r   r0   rF   rG   r9   rH   ZOBJECT_ID.__annotate__	  s     - -T -i -r8   c                	s@    \        V \        V4      P                  4      # r<   )rW   rq   r>   )r_   r      &&r9   	from_slotZOBJECT_ID.from_slot  s    sDJOO,,r8   r0   N))r1   r2   r3   r4   Z
CAPABILITYZCHUIDrt   ZFINGERPRINTSZSECURITYZFACIALZPRINTEDru   rv   rw   	DISCOVERYZKEY_HISTORYZIRISrx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rf   r   r7   r0   r8   r9   r   r      s    JENLHFGINIIKDHHHHHHHHHIIIIIIIIIIIK- -r8   r   c                  s.    ] tR tRt^ t^t^t^t^t^t	Rt
R# )
PIN_POLICYi  r0   N)r1   r2   r3   r4   DEFAULTNEVERZONCEALWAYS
MATCH_ONCEMATCH_ALWAYSr7   r0   r8   r9   r   r     s     GEDFJLr8   r   c                  s&    ] tR tRt^ t^t^t^tRtR# )TOUCH_POLICYi  r0   N)	r1   r2   r3   r4   r   r   r   CACHEDr7   r0   r8   r9   r   r     s    GEFFr8   r   c                s    V P                  4       p \        V 4      \        8  d   \        R 4      hV P	                  \        R4      # )z&PIN/PUK must be no longer than 8 bytess   )encodelenPIN_LENrP   Zljust)pinrA   r9   
_pin_bytesr   a  s6    
**,C
3x'ABB99Wg&&r8   c                s    V \         P                  8X  d   ^ # V R,          R8X  d
   V ^,          # V R,          R8X  d
   V ^,          # R# )r    i  ic  i   i c  N)r'   ZAUTH_METHOD_BLOCKED)swrA   r9   _retries_from_swr   h  sB    	R###	F{fDy	f	Dyr8   c                  s6    ] tR tRt$ R]R&   R]R&   R]R&   RtR# )	PinMetadatair  booldefault_valuerL   Ztotal_attemptsattempts_remainingr0   Nr1   r2   r3   r4   __annotations__r7   r0   r8   r9   r   r   r  s    r8   r   c                  s6    ] tR tRt$ R]R&   R]R&   R]R&   RtR	# )
ManagementKeyMetadataiy  rg   rn   r   r   r   touch_policyr0   Nr   r0   r8   r9   r   r   y  s    !!r8   r   c                  sZ    ] tR tRt$ R]R&   R]R&   R]R&   R]R	&   R
]R&   ]R 4       tRtR# )SlotMetadatai  r:   rn   r   
pin_policyr   r   r   Z	generatedbytespublic_key_encodedc                	sB    \        V P                  V P                  4      # r<   )_parse_device_public_keyrn   r   r?   rA   r9   
public_keyZSlotMetadata.public_key  s    't7N7NOOr8   r0   N)r1   r2   r3   r4   r   re   r   r7   r0   r8   r9   r   r     s3    OP Pr8   r   c                  s6    ] tR tRt$ R]R&   R]R&   R]R&   RtR# )	BioMetadatai  r   
configuredrL   r   temporary_pinr0   Nr   r0   r8   r9   r   r     s    r8   r   c                s    V ^
,          R RRR1,          pV\        VP                  R4      ^,           ^,          4      ,          pV^8X  d   V# \        V ^
,          V^,
          4      V,           # )
   Z04bNZ1)rr   Zcount_bcd)ZvallnZbitsr`   r9   r   r     s^    Bhs^TrT"DCC1$)**D74>SBYQ 7$ >>r8   c               rS   )rD   valueszdict[int, bytes | None]rE   r   r0   rF   rG   r9   rH   rH     s      2 u r8   c                sN    R P                  R V P                  4        4       4      # )r8   c              3  sH   "   T F  w  rVf   K  \        W4      x  K  	  R # 5ir<   )r    ).0Ztagvalue   &  r9   	<genexpr>Z!_dump_tlv_dict.<locals>.<genexpr>  s      *8JCEC.s   "")joinZitems)r   rA   r9   _dump_tlv_dictr     s&    88 *0,,.  r8   Z11010Z10110Z11111c                  s    ] tR tRt$ RtR]R&   R]R&   R]R&   R]R&   R]R&   R]R	&   R]R
&   R]R&   R]R&   R t]R R l4       tR t	Rt
R# )FascNi  zNFASC-N data structure

https://www.idmanagement.gov/docs/pacs-tig-scepacs.pdf
rL   agency_codeZsystem_codeZcredential_numberZcredential_seriesZindividual_credential_issueZperson_identifierZorganizational_categoryorganizational_identifierZ!organization_association_categoryc                	s   \        R  \        \        V 4      \        4       4       4      p\        \        V4      ,           \        ,           \        V4      ,           \        ,           \        V4      ,           \        ,           \        V4      ,           \        ,           \        V4      ,           \        ,           \        V4      ,           \        V4      ,           \        V4      ,           \        V4      ,           \        ,           p^ p\        ^ \        V4      ^4       F  pV\        W$V^,            ^4      ,          pK!  	  \        \        V^4      ^,          V,          4      # )c              3  s<   "   T F  w  r\        W4      x  K  	  R # 5ir<   )r   )r   Zvr   r   r9   r   Z"FascN.__bytes__.<locals>.<genexpr>  s     K+J%!$q+++Js   )Ziterzipr   _FASCN_LENSBCD_SSZnextBCD_FSBCD_ESranger   rL   r$   )r@   Zvsbslrcis   &    r9   	__bytes__ZFascN.__bytes__  s0   K3wt}k+JKK 2h 2h 	
 2h  2h  2h	 
 2h 2h 2h 2h  	( q#b'1%A3ra!e}a((C & Rq3.//r8   c               rS   )rD   r   r   rE   r   r0   rF   rG   r9   rH   ZFascN.__annotate__  s      u  r8   c           	     	s   a \        V4      R  p\        ^ ^^4       Uu. uF"  p\        W#V^,            RRR1,          ^4      NK$  	  upoV3R l\        R\        4       4       pV ! V!  # u upi )Z0200bNc           
   3  s|   <"   T F1  w  r\        R P                  R SWV,             4       4      4      x  K3  	  R# 5i) c              3  s8   "   T F  p\        V4      x  K  	  R # 5ir<   )rr   )r   drQ   r9   r   Z-FascN.from_bytes.<locals>.<genexpr>.<genexpr>  s     =(<1A(<s   N)rL   r   )r   Zoffsr   dss   &  r9   r   Z#FascN.from_bytes.<locals>.<genexpr>  s=      
 Q =4)(<==>>Ps   9<r   )	      i   i   i   i   i    i!   i%   )r#   r   rL   r   r   )r_   r   r   r   argsr   s   &&   @r9   
from_bytesZFascN.from_bytes  st    % '38C3CD3Cac"Q-"%q)3CD
   BKP

 Dz Es   (A)c                	s&    R \        V 4      ,          # )z$[%04d-%04d-%06d-%d-%d-%010d%d%04d%d])r   r?   rA   r9   rB   ZFascN.__str__  s    5EEr8   r0   N)r1   r2   r3   r4   __doc__r   r   rf   r   rB   r7   r0   r8   r9   r   r     s^    
 !$$  ""'**0>  Fr8   r   T)Zkw_onlyc                  s    ] tR tRt$ RtR]R&   R]R&   RtR]R&   RtR]R	&   RtR]R
&   R]R&   R]R&   Rt	R]R&   R]R&   Rt
R]R&   RR R llt]R R l4       tR t]R R l4       tRtR# )Chuidi  Nz
int | Nonebuffer_lengthr   fasc_nbytes | Noner   r   dunsr   guidr   expiration_dateauthentication_key_mapasymmetric_signaturer   c               rS   )rD   include_signaturer   rE   r   r0   rF   rG   r9   rH   Chuid.__annotate__  s     
 
D 
E 
r8   c                	s   \        ^V P                  e   \        V P                  4      MR^0\        V P                  4      ^1V P
                  ^2V P                  ^3V P                  ^4V P                  ^5V P                  P                  4       P                  RR4      P                  4       ^=V P                  ^>V'       d   V P                  MR\        V P                   e   \        V P                   .4      /
4      # R/
4      # )   NZ-r   r8   )r   r   r$   r   r   r   r   r   r   r   Z	isoformatZreplacer   r   r   TAG_LRCr   )r@   r   r   r9   
_get_bytesZChuid._get_bytes  s    %%1   2 23eDKK(d&&d44diidiid**446>>sBGNNPd113Dd//$dhh.Bz*
 	
 IL
 	
r8   c               rC   )rD   rE   r   r0   rF   rG   r9   rH   r     s     8 85 8r8   c                	s&    V P                  R R7      # )F)r   r   r?   rA   r9   	tbs_bytesZChuid.tbs_bytes  s    77r8   c                	s"    V P                  4       # r<   r   r?   rA   r9   r   ZChuid.__bytes__	  s      r8   c               rS   )rD   r   r   rE   r   r0   rF   rG   r9   rH   r     s     
 
u 
 
r8   c                	sD   \         P                  ! V4      pVP                  ^4      pVP                  \        4      pV^5,          p\	        \        VR,          4      \        VR,          4      \        VR,          4      4      pT ! V'       d   \        V4      MR\        P                  V^0,          4      VP                  ^14      VP                  ^24      VP                  ^34      V^4,          TVP                  ^=4      V^>,          V'       d   V^ ,          R7
      # RR7
      # )r   :N   N:r   r   N:r      NN)
r   r   r   r   r   r   r   r   r   r   )	r    
parse_dictgetr   r   rL   r#   r   r   )r_   r   datar   r   r   r   s   &&     r9   r   ZChuid.from_bytes  s    ~~e$hhwJs1R5z3qv;AcFD6C)M2##DJ/&*hhtn$d+#'88D>!%dA
 	
 $(
 	
r8   r0   T)r1   r2   r3   r4   r   r   r   r   r   r   r   r   re   r   r   rf   r   r7   r0   r8   r9   r   r     s     $M:$M $K$.2|2D,
K+/L/C
$ 8 8! 
 
r8   r   c                s.   V \         P                  \         P                  39   d   V# V P                  \        P
                  8X  d   \        V\        4      '       d   TpM@\        P                  ! V\        4       4      pVP                  V4       VP                  4       pV P                  ^,          p\        V4      V8  d   VP                  V^,          R4      # VRV # V P                  \        P                   8X  d   Rp\"        P$                  ! WpP                  \        4       4      pVP'                  WV4      p	VP)                  4       P+                  4       P,                  p
\/        \1        \3        V	4      Wz4      V P                  ^,          4      # R# )r       N  )r:   rM   rN   rJ   r/   r5   rU   r   r   ZHashr   updatefinalizerR   r   Zrjustr6   r   generate_private_keysignr   public_numbersnr$   powr#   )rn   messagehash_algorithmpaddingZhashedZhZbyte_lenedummyZ	signaturer   s   &&&&       r9   _pad_messager   "  s2   H$$hoo66Y\\)ni00FNO,=>AHHWZZ\F##q(v;!<<Au55ix  			y}}	,((,<,<o>OPJJw@	--/11Yy118(:J:Ja:OPP 
-r8   c                s(   R p\         P                  ! V\        V 4      ^,          \        4       4      pVP	                  4       P                  4       P                  p\        \        \        V 4      W$4      \        V 4      4      pVP                  WQ4      # )r   )r   r   r   r   r   r   r   r$   r   r#   decrypt)paddedr   r   r   r   	encrypted   &&    r9   _unpad_messager   :  sn    A$$QFa9JKE))+--A#i/6FDI==,,r8   c               s0    V ^8  d   QhRRRRRRRRR	R
RR/# )rD   versionr!   rn   r:   r   r   r   r   generater   rE   Noner0   rF   rG   r9   rH   rH   C  sL     Q QQQ Q 	Q
 Q 
Qr8   c                sV    \         P                  ! R\        4       \        WW#V4       R# )a  Check if a key type is supported by a specific YubiKey firmware version.

This method will return None if the key (with PIN and touch policies) is supported,
or it will raise a NotSupportedError if it is not.

:deprecated: Use PivSession.check_key_support() instead.
z7Deprecated: use PivSession.check_key_support() instead.N)warningswarnDeprecationWarning_do_check_key_support)r   rn   r   r   r   s   &&&&&r9   check_key_supportr  C  s$     MMA 'ZxPr8   c               s4    V ^8  d   QhRRRRRRRRR	R
RR
RR/# )rD   r   r!   rn   r:   r   r   r   r   r   r   fips_restrictionsrE   r   r0   rF   rG   r9   rH   rH   X  sW     &Y &Y&Y&Y &Y 	&Y
 &Y &Y 
&Yr8   c                s   V\         P                  8X  d   \        V R	R4       V\        P                  8w  g   V\
        P                  8w  d   \        V R	R4       V\        P                  8X  d   \        V R
R4       RT u;8:  d   R8  d6   M M2V'       d+   VP                  \        P                  8X  d   \        R4      hV'       g   RT u;8:  d   R8  dT   M MPV\         P                  \         P                  39   d   \        R4      hV\
        P                  8X  d   \        R4      hV\         P                  \         P                  \         P                   \         P                  39   d   \        V RV R24       R# R# )r   z#ECCP384 requires YubiKey 4 or laterz,PIN/Touch policy requires YubiKey 4 or laterz1Cached touch policy requires YubiKey 4.3 or laterz0RSA key generation not supported on this YubiKeyz&RSA 1024 not supported on YubiKey FIPSz,PIN_POLICY.NEVER not allowed on YubiKey FIPSz requires YubiKey 5.7 or laterN)r   r    r    r   rj   r    )r   rD   r    )r   rj      )r   r   r    )r   r  r    r  i   r    )r:   r\   r%   r   r   r   r   rJ   r/   r6   r   rb   rN   r   rc   rd   rM   )r   rn   r   r   r   r     &&&&&&r9   r  r  X  s3    8###,QR|+++zZ=O=O/OY N	
 |***Y S	

 G'i'**imm;#$VWW I<9<(((//::#$LMM)))#$RSS 	  	xj8V,WXr8   c                s   \         P                  ! V4      pV P                  \        P                  8X  dR   \        V^,          4      p\        V^,          4      p\        P                  ! WC4      P                  \        4       4      # V \        P                  8X  d'   \        P                  P                  V^,          4      # V \        P                  8X  d'   \         P"                  P                  V^,          4      # V \        P$                  8X  d   \&        P(                  pM\&        P*                  p\&        P,                  P/                  V! 4       V^,          4      # )i   )r    r   rJ   r/   r6   r#   r   ZRSAPublicNumbersr   r   r:   rM   r   r]   Zfrom_public_bytesrN   r   r^   r[   r   Z	SECP256R1Z	SECP384R1rY   Zfrom_encoded_point)rn   Zencodedr   ZmodulusZexponentrZ   r   r9   r   r     s    >>'"DY]]*DJ'T$Z(##H6AA/BSTT	X%%	%''99$t*EE	X__	$%%77T
CCx''',.LLELLE((;;EGT$ZPPr8   a  
MIIBOTCCASOgAwIBAgIBATANBgkqhkiG9w0BAQUFADAZMRcwFQYDVQQDEw5odHRw
Oi8vd3d3LmNvbTAeFw0xMDA1MTExOTEzMDNaFw0xMTA1MTExOTEzMDNaMF8xEDAO
BgkqhkiG9w0BCQEWAUAxCjAIBgNVBAMTASAxCzAJBgNVBAYTAlVTMQswCQYDVQQI
EwJXSTELMAkGA1UEChMCb24xDDAKBgNVBAsTA291bjEKMAgGA1UEBRMBIDAfMA0G
CSqGSIb3DQEBAQUAAw4AMAsCBG6G5ZUCAwEAAaNNMEswCQYDVR0TBAIwADAdBgNV
HQ4EFgQUHSkK6busCxxK6PKpBlL9q8K1mcQwHwYDVR0jBBgwFoAUn7r/DVMuEpK9
Rxq3nyiLml10+nQwDQYJKoZIhvcNAQEFBQADAQA=
c               s     V ^8  d   QhRRRR/# )rD   	cert_datar   rE   r0   rF   rG   r9   rH   rH     s     !? !?e !? !?r8   c                s
   \         P                  R4       V R,          R8X  d   \        P                  V R,          R4      p\        P
                  ! \        P                  \        R7      p VP                  V R,          4      p \        V 4      V8w  d,   \         P                  RV\        V 4      4       \        R	4      h\         P                  R
4       V #  \        P                  ! V 4      p \         P                  R4       V #   \        P                  \        3 d    \         P                  R4        L`i ; i  \        P                  \        P                  3 d    \         P                  R4        Mi ; i\        R4      h)z<
Decompress a compressed certificate using various methods.
z+Certificate is compressed, decompressing...:NrD   Ns    :rD   r   NZlittle)ZwbitsZzdict:r   NNz3Unexpected decompressed length, expected %d, got %dz2Decompressed length does not match expected lengthz0Decompressed certificate with CXF deflate formatz$Failed to decompress with CXF formatz/Decompressed certificate with basic gzip formatz-Failed to decompressed with basic gzip formatz Failed to decompress certificate)loggerdebugrL   r   zlibZdecompressobjZ	MAX_WBITS_cxf_dictionaryZ
decompressr   ZerrorrP   ZwarninggzipZBadGzipFiler   )r	  Zexpected_lengthZdecompressorr   r9   decompress_certificater    s5    LL>? }	!..3B))oV	C$//	">I9~0I#	N
 !!UVVLLKL
HOOI.	FG 

J' 	CNNAB	C JJ(() HFGH =
>>s%   ,A)D ,D: 0D76D7::E76E7c                  s   ] tR tRtRtRPR R llt]R R l4       t]R R	 l4       tR
 R lt	R R lt
]R R l4       t]R R l4       tR R ltRQR R lltR R ltRRR R lltR R ltR R ltR R ltR  R! ltR" R# ltR$ R% ltR& R' ltR( R) ltR* R+ ltR, R- ltR. R/ ltRPR0 R1 lltR2 R3 ltR4 R5 ltR6 R7 ltRPR8 R9 lltR: R; lt RQR< R= llt!R> R? lt"]#PH                  ]%PH                  3R@ RA llt&]#PH                  ]%PH                  3RB RC llt'RD RE lt(RF RG lt)RH RI lt*RJ t+RK t,RL t-RQRM RN llt.ROt/R# )S
PivSessioni  z#A session with the PIV application.Nc               rS   )rD   
connectionr*   scp_key_paramszScpKeyParams | Noner0   rF   rG   r9   rH   PivSession.__annotate__  s"     J J'J ,Jr8   c           
     	s   \        V4      V n        V P                  P                  \        P                  4       V'       d   V P                  P                  V4       \        P                  R 4       \        P                  ! \        P                  ! V P                  P                  ^ \        ^ ^ 4      4      4      V n        V P                  P                  V P                   4        V P#                  4       P$                  V n        ^V n        ^V n        \        P                  RV P                    R24       R#   \(         d    \*        P,                  T n         LUi ; i)zGetting PIV versionz!PIV session initialized (version=rs   N)r+   protocolZselectr&   ZPIVZinit_scpr
  r  r"   Zpatchr!   r   	send_apduINS_GET_VERSION_versionZ	configurer   get_management_key_metadatarn   _management_key_typer   rg   ri   _current_pin_retries_max_pin_retries)r@   r  r     &&&r9   __init__ZPivSession.__init__  s    
 **5SWW%MM"">2*+)//t}}66q/1aPQ
 	-	A(,(H(H(J(S(SD% %&! !8aHI	 ! 	A(;(@(@D%	As   'D9 9 EEc               rC   )rD   rE   r!   r0   rF   rG   r9   rH   r    s       r8   c                r;   )zOThe version of the PIV application,
typically the same as the YubiKey firmware.)r  r?   rA   r9   r   ZPivSession.version  s     }}r8   c               rC   )rD   rE   rg   r0   rF   rG   r9   rH   r    s     ) )%8 )r8   c                r;   )z5The algorithm of the management key currently in use.)r  r?   rA   r9   management_key_typeZPivSession.management_key_type  s     (((r8   c               rC   rD   rE   r   r0   rF   rG   r9   rH   r    s     3< 3<t 3<r8   c                s,   \         P                  R4        V P                  4       P                  '       d   \	        R4      h \         P                  R4       V P                  4       pV^ 8  d    V P                  R4       K  \         P                  R4       \         P                  R4        V P                  4       P                  pV^ 8  d     V P                  \        \        RR4       K&  \         P                  R4       \         P                  R	4       V P                  P                  ^ \         ^ ^ 4       ^V n        ^V n         V P'                  4       P(                  V n        \         P1                  R
4       R#   \
         d     ELJi ; i  \         d   pTP                  p Rp?EKG  Rp?ii ; i  \
         d    ^p Li ; i  \         d   pTP                  p Rp?EK   Rp?ii ; i  \
         d    \,        P.                  T n         Li ; i)zFactory reset the PIV application data.

This deletes all user-data from the PIV application, and resets the default
values for PIN, PUK, and management key.
zPreparing PIV resetz7Cannot perform PIV reset when biometrics are configuredz.Verify PIN with invalid attempts until blockedr   NzPIN is blockedz.Verify PUK with invalid attempts until blockedzPUK is blockedzSending resetz$PIV application data reset performed)r
  r  get_bio_metadatar   rP   r   get_pin_attempts
verify_pinr   r   get_puk_metadata_change_referenceINS_RESET_RETRYPIN_P2r  r  	INS_RESETr  r  r  rn   r  rg   ri   info)r@   Zcounterr   r   r9   resetZPivSession.reset  s    	*+	$$&111 M  2 	EF'')k/# 	%& 	EF	++-@@G k/&&BG 	%& 	_%9a3$%! !	A(,(H(H(J(S(SD% 	:;M ! 		 # /../ ! 	G	
 # /../ ! 	A(;(@(@D%	Asj   E? E? 0F .F7 G
 	G0 ?FFF4F//F47GG
G-G((G-0 HHc               rC   rK   r0   rF   rG   r9   rH   r  #  s     # #C #r8   c                s    \         P                  R4       \        V P                  R4       V P                  P                  ^ \        ^ ^ 4      p\        V4      # )z%Get the serial number of the YubiKey.zGetting serial number)r  r    rj   )r
  r  r%   r   r  r  INS_GET_SERIALr#   )r@   responserQ   r9   
get_serialZPivSession.get_serial#  sB    ,-i0==**1naC""r8   c               rS   )rD   ro   r   rE   r   r0   rF   rG   r9   rH   r  +  s    >>5>T>r8   c                	    R # r<   r0   )r@   ro   r   r9   authenticatePivSession.authenticate*  s    ;>r8   c               $    V ^8  d   QhRRRRRR/# )rD   rn   rg   ro   r   rE   r   r0   rF   rG   r9   rH   r  /  s$      +=B	r8   c                	r-  r<   r0   )r@   rn   ro   r  r9   r.  r/  -  s     r8   c               rC   r  r0   rF   rG   r9   rH   r  3  s     8C 8Ct 8Cr8   c                s   VP                  R4      pVP                  R4      p\        V4      ^8X  d   Vw  r4M<\        V4      ^8X  d   V^ ,          pM"VP                  R4      pVP                  R4      pV'       d8   \        P                  ! R\        4       V P
                  V8w  d   \        R4      h\        V\        4      '       g   \        R4      hV P
                  p\        P                  RV 24       V P                  P                  ^ \        V\        \!        \"        \!        \$        4      4      4      p\         P&                  ! \$        \         P&                  ! \"        V4      4      p\(        P*                  ! VP,                  4      p\/        4       p\1        W44      p	\3        V	\4        P6                  ! 4       V4      p
V
P9                  4       pVP;                  V4      VP=                  4       ,           pV P                  P                  ^ \        V\        \!        \"        \!        \$        V4      \!        \>        V4      ,           4      4      p\         P&                  ! \@        \         P&                  ! \"        V4      4      pV
PC                  4       pVP;                  V4      VP=                  4       ,           p\E        W4      '       g   \G        R4      hR# )	zhAuthenticate to PIV with management key.

:param bytes management_key: The management key in raw bytes.
rn   ro   zDDeprecated: call authenticate() without passing management_key_type.zIncorrect management key typezmanagement_key must be byteszAuthenticating with key type: zDevice response is incorrectN)$r   r   r   r   r  r  rP   rU   r   Z	TypeErrorr
  r  r  r  INS_AUTHENTICATESLOT_CARD_MANAGEMENTr    TAG_DYN_AUTHTAG_AUTH_WITNESSunpackosZurandomrl   r   rp   r   r   ZECB	decryptorr   r   TAG_AUTH_CHALLENGETAG_AUTH_RESPONSE	encryptorr   r   )r@   r   Zkwargsrn   ro   r+  ZwitnessZ	challengeZbackendZ
cipher_keyZcipherr7  Z	decryptedr   r:  expecteds   &*,             r9   r.  r/  3  s-   
 ::j)$45t9>'+$HnY!^!!WNzz*-H#ZZ(89NMMV" ''83 !@AA.%00:;;++5hZ@A==** c"234
 **-szz,/QRJJx556	!#*8D

EIIK9$$&	$$W-	0B0B0DD	==** $i037I93UU	
 JJ0#**\82TU	$$&	##I.1C1C1EE,,"#ABB -r8   c               (    V ^8  d   QhRRRRRRRR/# )	rD   rn   rg   ro   r   require_touchr   rE   r   r0   rF   rG   r9   rH   r  m  s2     * *%* * 	*
 
*r8   c                s   \        V4      p\        P                  RV 24       V\         P                  8w  d   \	        V P
                  R4       \        V4      VP                  8w  d   \        RVP                  ,          4      hV P                  P                  ^ \        ^V'       d   ^M^\        V4      \        \        V4      ,           4       Wn        \        P!                  R4       R# )zSet a new management key.

:param key_type: The management key type.
:param management_key: The management key in raw bytes.
:param require_touch: The touch policy.
z Setting management key of type: zManagement key must be %d byteszManagement key setN)r  r   r    )rg   r
  r  ri   r%   r   r   rk   rP   r  r  INS_SET_MGMKEYr$   r    r2  r  r(  )r@   rn   ro   r=  s   &&&&r9   set_management_keyZPivSession.set_management_keym  s     'x07zBC*///DLL)4~("2"22>AQAQQRR!Dth#&:N"KK	
 %-!()r8   c               rS   )rD   r   rr   rE   r   r0   rF   rG   r9   rH   r    s     + +c +d +r8   c           	     s0   \         P                  R4        V P                  P                  ^ \        ^ \
        \        V4      4       V P                  V n        R#   \         d1   p\        TP                  4      pTf   h Y0n        \        T4      hRp?ii ; i)zVerify the user by PIN.

NOTE: InvalidPinError raised from this method will cap remaining_attempts
at 15, even if the true number of remaining attempts is higher.

:param pin: The PIN.
zVerifying PINN)r
  r  r  r  
INS_VERIFYr&  r   r  r  r(   r   r   r   r@   r   r   retries   &&  r9   r"  ZPivSession.verify_pin  sx     	_%	+MM##Az1fjoN(,(=(=D% 	+&qtt,G(/%!'**	+s   AA B%+BBc               $    V ^8  d   QhRRRRRR/# )rD   r   r   
check_onlyrE   r   r0   rF   rG   r9   rH   r    s$     (3 (3!(37;(3	(3r8   c                s   \         P                  R4       V'       d   V'       d   \        R4      hV'       d   RpMV'       d   \        ^4      pM\        ^4      p V P                  P                  ^ \        ^ \        V4      pT'       d   T# R#   \         dZ   pTP                  \        P                  8X  d   \        R4      h\        TP                  4      pTf   h \        TRT R24      hRp?ii ; i)a/  Verify the user by fingerprint (YubiKey Bio only).

Fingerprint verification will allow usage of private keys which have a PIN
policy allowing MATCH. For those using MATCH_ALWAYS, the fingerprint must be
verified just prior to using the key, or by first requesting a temporary PIN
and then later verifying the PIN just prior to key use.

:param temporary_pin: Request a temporary PIN for later use within the session.
:param check_only: Do not verify the user, instead immediately throw an
    InvalidPinException containing the number of remaining attempts.
zVerifying UVz?Cannot request temporary PIN when doing check-only verificationr8   4Biometric verification not supported by this YuibKeyNzFingerprint mismatch,  attempts remaining)r
  r  rP   r    r  r  r@  SLOT_OCC_AUTHr(   r   r'   REFERENCE_DATA_NOT_FOUNDr   r   r   )r@   r   rE  r   r+  r   rB  s   &&&    r9   	verify_uvZPivSession.verify_uv  s     	^$ZQ  Dq6Dq6D	}}..q*aPTUH )x2d2  
	ttr222'J  'qtt,G!1':MN 
	s   'B C3AC..C3c               rS   )rD   r   r   rE   r   r0   rF   rG   r9   rH   r    s       $ r8   c           
     s   \         P                  R4       \        V4      \        8w  d   \	        R\         R24      h V P
                  P                  ^ \        ^ \        \        ^V4      4       R#   \         dZ   pTP                  \        P                  8X  d   \        R4      h\        TP                  4      pTf   h \!        TRT R24      hRp?ii ; i)zdVerify the user via temporary PIN.

:param pin: A temporary PIN previously requested via verify_uv.
zVerifying temporary PINzTemporary PIN must be exactly  bytesrF  NzInvalid temporary PIN, rG  )r
  r  r   TEMPORARY_PIN_LENrP   r  r  r@  rH  r    r(   r   r'   rI  r   r   r   rA  rC  r9   verify_temporary_pinZPivSession.verify_temporary_pin  s    
 	./s8((=>O=PPVWXX	MM##Az1mSC[Q 
	ttr222'J  'qtt,G!27);NO 
	s   1A1 1C<ACCc               rC   rK   r0   rF   rG   r9   rH   r    s      # r8   c                s   \         P                  R4        V P                  4       P                  #   \         d     T P
                  P                  ^ \        ^ \        4       \         P                  R4       T P                  u #   \         dD   p\        TP                  4      pTf   h Y n	        \         P                  R4       Tu Rp?u # Rp?ii ; ii ; i)zGet remaining PIN attempts.zGetting PIN attemptsz%Using cached value, may be incorrect.NzUsing value from empty verify)r
  r  get_pin_metadatar   r   r  r  r@  r&  r  r(   r   r   )r@   r   rB  r   r9   r!  ZPivSession.get_pin_attempts  s    +,	((*===  	'':q&ADE000 *1440?,3)<=	s9   1 CABCC6CCCCCc               rD  )rD   old_pinrr   new_pinrE   r   r0   rF   rG   r9   rH   r    s!     # ## # # #r8   c                s    \         P                  R4       V P                  \        \        W4       \         P                  R4       R# )zChange the PIN.

NOTE: InvalidPinError raised from this method will cap remaining_attempts
at 15, even if the true number of remaining attempts is higher.

:param old_pin: The current PIN.
:param new_pin: The new PIN.
zChanging PINNew PIN setN)r
  r  r$  INS_CHANGE_REFERENCEr&  r(  )r@   rO  rP  r  r9   
change_pinZPivSession.change_pin  s/     	^$3VWNM"r8   c               rD  )rD   old_pukrr   new_pukrE   r   r0   rF   rG   r9   rH   r    s!      #   r8   c                   \         P                  R4        V P                  \        \        W4       \         P                  R4       R#   \         d1   pTP                  \        P                  8X  d   \        R4      hh Rp?ii ; i)zChange the PUK.

NOTE: InvalidPinError raised from this method will cap remaining_attempts
at 15, even if the true number of remaining attempts is higher.

:param old_puk: The current PUK.
:param new_puk: The new PUK.
zChanging PUKzNew PUK setz,Setting PUK is not supported on this YubiKeyN)r
  r  r$  rR  PUK_P2r(  r(   r   r'   INVALID_INSTRUCTIONr   )r@   rT  rU  r      &&& r9   
change_pukZPivSession.change_puk  se     	^$	""#7RKK& 	ttr---'(VWW	   0A	 	B+A??Bc               rD  )rD   pukrr   rP  rE   r   r0   rF   rG   r9   rH   r    s!      s S T r8   c                rV  )zReset PIN with PUK.

NOTE: InvalidPinError raised from this method will cap remaining_attempts
at 15, even if the true number of remaining attempts is higher.

:param puk: The PUK.
:param new_pin: The new PIN.
zUsing PUK to set new PINrQ  z/Unblocking PIN is not supported on this YubiKeyN)r
  r  r$  r%  r&  r(  r(   r   r'   rX  r   )r@   r\  rP  r   rY  r9   unblock_pinZPivSession.unblock_pin  sk     	/0	""?FCIKK& 	ttr---'E  	r[  c               rD  )rD   pin_attemptsrL   puk_attemptsrE   r   r0   rF   rG   r9   rH   r  $  s!      S   r8   c                s@   \         P                  RV RV R24        V P                  P                  ^ \        W4       Wn        Wn        \         P                  R4       R#   \         d1   pTP                  \        P                  8X  d   \        R4      hh Rp?ii ; i)zSet PIN retries for PIN and PUK.

Both PIN and PUK will be reset to default values when this is executed.

Requires authentication with management key and PIN verification.

:param pin_attempts: The PIN attempts.
:param puk_attempts: The PUK attempts.
zSetting PIN/PUK attempts (z, rs   zPIN/PUK attempts setz2Setting PIN attempts not supported on this YubiKeyN)r
  r  r  r  INS_SET_PIN_RETRIESr  r  r(  r(   r   r'   rX  r   )r@   r^  r_  r   rY  r9   set_pin_attemptsZPivSession.set_pin_attempts$  s     	1,r,qQR
	MM##A':LW$0!(4%KK./ 	ttr---'H  	s   AA" "B-+BBc               rC   rD   rE   r   r0   rF   rG   r9   rH   r  ;       2 2+ 2r8   c                V    \         P                  R4       V P                  \        4      # )zGet PIN metadata.zGetting PIN metadata)r
  r  _get_pin_puk_metadatar&  r?   rA   r9   rN  ZPivSession.get_pin_metadata;       +,))&11r8   c               rC   rb  r0   rF   rG   r9   rH   r  @  rc  r8   c                rd  )zGet PUK metadata.zGetting PUK metadata)r
  r  re  rW  r?   rA   r9   r#  ZPivSession.get_puk_metadata@  rf  r8   c               rC   )rD   rE   r   r0   rF   rG   r9   rH   r  E  s     
 
-B 
r8   c                s   \         P                  R4       \        V P                  R4       \        P
                  ! V P                  P                  ^ \        ^ \        4      4      pV\        ,          p\        \        VP                  \        R4      ^ ,          4      V\        ,          R8g  \!        V\"        ,          4      4      # )zGet management key metadata.zGetting management key metadatas   r   r  rj   r    )r
  r  r%   r   r    r   r  r  INS_GET_METADATAr2  TAG_METADATA_POLICYr   rg   r   TAG_METADATA_ALGOTAG_METADATA_IS_DEFAULTr   INDEX_TOUCH_POLICY)r@   r   policyr   r9   r  Z&PivSession.get_management_key_metadataE  s    67i0~~MM##A'7<PQ
 )*$):G DQ GH()U2 234
 	
r8   c               rS   )rD   r   rq   rE   r   r0   rF   rG   r9   rH   r  S  s     
 
d 
| 
r8   c                s   \        V4      p\        P                  RV 24       \        V P                  R4       \
        P                  ! V P                  P                  ^ \        ^ V4      4      pV\        ,          p\        \        V\        ,          ^ ,          4      \        V\        ,          4      \!        V\"        ,          4      V\$        ,          ^ ,          \&        8H  V\(        ,          4      # )z@Get slot metadata.

:param slot: The slot to get metadata from.
zGetting metadata for slot rg  )rq   r
  r  r%   r   r    r   r  r  rh  ri  r   r:   rj  r   INDEX_PIN_POLICYr   rl  TAG_METADATA_ORIGINORIGIN_GENERATEDTAG_METADATA_PUBLIC_KEY)r@   r   r   rm  rC  r9   get_slot_metadataZPivSession.get_slot_metadataS  s    
 Dz1$89i0~~dmm55a9I1dST)*T+,Q/0v./0 234$%a(,<<()
 	
r8   c               rC   )rD   rE   r   r0   rF   rG   r9   rH   r  e  s     
 
+ 
r8   c           	     s   \         P                  R4        \        P                  ! V P                  P                  ^ \        ^ \        4      4      p\        ^TP                  \         R4      ^ ,          8H  T\"        ,          ^ ,          ^TP                  \$        R4      ^ ,          8H  4      #   \         dA   pTP                  \        P                  \        P                  39   d   \        R4      hh Rp?ii ; i)zGet YubiKey Bio metadata.

This tells you if fingerprints are enrolled or not, how many fingerprint
verification attempts remain, and whether or not a temporary PIN is currently
active.
zGetting bio metadatarF  Nr   )r
  r  r    r   r  r  rh  rH  r(   r   r'   rI  rX  r   r   r   TAG_METADATA_BIO_CONFIGUREDTAG_METADATA_RETRIESTAG_METADATA_TEMPORARY_PIN)r@   r   r   r   r9   r   ZPivSession.get_bio_metadatae  s     	+,		>>''+;QND 5w?BB%&q)4g>qAA
 	
  	tt33R5K5KLL'J  	s   :B, ,C77;C22C7c               s0    V ^8  d   QhRRRRRRRRR	R
RR/# )rD   r   rq   rn   r:   r   r   r   zhashes.HashAlgorithm | Noner   zAsymmetricPadding | NonerE   r0   rF   rG   r9   rH   r  }  sN     D DD D 	D
 4D *D 
Dr8   c           
     s    \        V4      p\        V4      p\        P                  RV RV RV RV 24       \	        W#WE4      pV P                  WVR4      # )a   Sign message with key.

Requires PIN verification.

:param slot: The slot of the key to use.
:param key_type: The type of the key to sign with.
:param message: The message to sign.
:param hash_algorithm: The pre-signature hash algorithm to use.
:param padding: The pre-signature padding.
zSigning data with key in slot 	 of type z using hash=z
, padding=F)rq   r:   r
  r  r   _use_private_key)r@   r   rn   r   r   r   r   s   &&&&&& r9   r   ZPivSession.sign}  sj    $ DzH%,TF)H: F"#:gY8	
 hI$$TVUCCr8   c               s(    V ^8  d   QhRRRRRRRR/# )rD   r   rq   cipher_textr   r   r   rE   r0   rF   rG   r9   rH   r    s,     / //',/7H/	/r8   c                s   \        V4      p \        \        R\        V4      ^,           24      p\        P                  RT RT RT 24       T P                  YTR4      p\        YS4      #   \         d    \        R4      hi ; i)zDecrypt cipher text.

Requires PIN verification.

:param slot: The slot.
:param cipher_text: The cipher text to decrypt.
:param padding: The padding of the plain text.
r6   zInvalid length of ciphertextz!Decrypting data with key in slot rv  z using padding=F)
rq   rW   r:   r   rX   rP   r
  r  rw  r   )r@   r   rx  r   rn   r   s   &&&&  r9   r   ZPivSession.decrypt  s     Dz	=x3s;/?!/C.D)EFH 	/vYxj Ii!	
 &&t{EJf..  	=;<<	=s   #A, ,Bc               r0  )rD   r   rq   peer_public_keyzCec.EllipticCurvePublicKeyWithSerialization | x25519.X25519PublicKeyrE   r   r0   rF   rG   r9   rH   r    s.     A AA P	A 
Ar8   c                s   \        V4      p\        P                  V4      pVP                  \        P
                  8w  d   \        R4      h\        P                  RV RV 24       V\        P                  8X  d0   VP                  \        P                  \        P                  4      pM.VP                  \        P                  \        P                  4      pV P!                  WVR4      # )zCalculate shared secret using ECDH.

Requires PIN verification.

:param slot: The slot.
:param peer_public_key: The peer's public key.
zUnsupported key typez*Performing key agreement with key in slot rv  T)rq   r:   ra   rJ   r/   r5   rP   r
  r  rN   public_bytesr   Rawr   ZX962ZUncompressedPointrw  )r@   r   ry  rn   r   s   &&&  r9   calculate_secretZPivSession.calculate_secret  s     Dz++O<-3448izR	
 x&"//l>N>NOD"//|==D $$TT4@@r8   c               rS   )rD   	object_idrL   rE   r   r0   rF   rG   r9   rH   r    s     ? ?C ?E ?r8   c                sz   \         P                  R\        V4       24       V\        P                  8X  d   \        P                  pM\
        p \        P                  ! VV P                  P                  ^ \        ^?^\        \        \        V4      4      4      4      #   \         d   p\        RT4      hRp?ii ; i)znGet object by ID.

Requires PIN verification for protected objects.

:param object_id: The object identifier.
zReading data from object slot zMalformed object dataN)r
  r  hexr   r   TAG_OBJ_DATAr    r5  r  r  INS_GET_DATA
TAG_OBJ_IDr$   rP   r   )r@   r}  r;  r   rC  r9   
get_objectZPivSession.get_object  s     	5c)n5EFG	+++%//H#H	?::'' 
Ii$89	 	  	?"#:A>>	?s   AB B:)B55B:c               r0  )rD   r}  rL   r   r   rE   r   r0   rF   rG   r9   rH   r    s&     E EC E| Et Er8   c                s    V P                   P                  ^ \        ^?^\        \        \        V4      4      \        \        T;'       g    R4      ,           4       \        P                  R\        V4       24       R# )zWrite data to PIV object.

Requires authentication with management key.

:param object_id: The object identifier.
:param data: The object data.
r8   zData written to object slot N)
r  r  INS_PUT_DATAr    r  r$   r  r
  r(  r~  )r@   r}  r   r  r9   
put_objectZPivSession.put_object  s^     	
Ii01Cdkkc4RR	
 	23y>2BCDr8   c               rS   rD   r   rq   rE   x509.Certificater0   rF   rG   r9   rH   r    s     = =D =-= =r8   c                s   \        V4      p\        P                  RV 24        \        P                  ! V P                  \        P                  V4      4      4      pV\        ,          p\        V9   d   V\        ,          ^ ,          M^ pT^8X  d   \        T4      pMT^ 8w  d   \        R4      h \        P                   ! T\#        4       4      #   \        \        3 d    \        R4      hi ; i  \$         d   p\        RT4      hRp?ii ; i)zOGet certificate from slot.

:param slot: The slot to get the certificate from.
zReading certificate in slot z!Malformed certificate data objectzUnsupported value in CertInfozInvalid certificateN)rq   r
  r  r    r   r  r   r   TAG_CERTIFICATETAG_CERT_INFOrP   ZKeyErrorr   r  r   r   load_der_x509_certificater   Z	Exception)r@   r   r   r	  	cert_infor   r   r9   get_certificateZPivSession.get_certificate  s    
 Dz3D6:;	H>>$//)2E2Ed2K"LMD_-I2?42G]+A.QI >.y9I!^#$CDD	=11)_=NOO H% 	H"#FGG	H  	="#8!<<	=s$   A&C 1C0 C-0D;DDc               r<  )	rD   r   rq   certificater  compressr   rE   r   r0   rF   rG   r9   rH   r    s2     S SS'7SCGS	Sr8   c                sN   \        V4      p\        P                  RV 24       VP                  \        P
                  4      p\        P                  R\        V4       RV 24       V'       d<   Rp\        P                  ! V4      p\        P                  R\        V4       R24       MRp\        \        V4      \        \        V4      ,           \        \        4      ,           pV P                  \        P                  V4      V4       \        P!                  RV R	V 24       R
# )zImport certificate to slot.

Requires authentication with management key.

:param slot: The slot to import the certificate to.
:param certificate: The certificate to import.
:param compress: If the certificate should be compressed or not.
zStoring certificate in slot zCertificate is z bytes, compression=s   zCompressed size: rK  r   zCertificate written to slot z, compression=N)rq   r
  r  rz  r   ZDERr   r  r  r    r  r  r   r  r   r   r(  )r@   r   r  r  r	  r  r   s   &&&&   r9   put_certificateZPivSession.put_certificate  s     Dz3D6:;,,X\\:	s9~&66J8*UVIi0ILL,S^,<FCDI+-+,'l 	
 		++D14824&xjQRr8   c               rS   rD   r   rq   rE   r   r0   rF   rG   r9   rH   r  .  s     	3 	3t 	3 	3r8   c                s    \        V4      p\        P                  RV 24       V P                  \        P                  V4      4       R# )zyDelete certificate.

Requires authentication with management key.

:param slot: The slot to delete the certificate from.
zDeleting certificate in slot N)rq   r
  r  r  r   r   r@   r   r   r9   delete_certificateZPivSession.delete_certificate.  s8     Dz4TF;<	++D12r8   c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )rD   r   rq   private_keyr.   r   r   r   r   rE   r:   r0   rF   rG   r9   rH   r  9  s<     8 88  8 	8
 #8 
8r8   c           	     s   \        V4      p\        P                  VP                  4       4      pV P	                  WSVR4       VP
                  ^,          pVP                  \        P                  8X  d   VP                  4       pTpVP                  P                  R8w  d   \        R4      hV^,          p\        ^\        VP                  V4      4      \        ^\        VP                   V4      4      ,           \        ^\        VP"                  V4      4      ,           \        ^\        VP$                  V4      4      ,           \        ^\        VP&                  V4      4      ,           pMV\        P(                  \        P*                  39   dZ   \        V\        P(                  8X  d   ^M^VP-                  \.        P0                  \2        P0                  \5        4       4      4      pM2VP                  4       pTp\        ^\        VP6                  V4      4      pV'       d!   V\        \8        \        V4      4      ,          pV'       d!   V\        \:        \        V4      4      ,          p\<        P?                  RV RV 24       V P@                  PC                  ^ \D        WQV4       \<        PG                  RV RV 24       V# )zImport a private key to slot.

Requires authentication with management key.

:param slot: The slot to import the key to.
:param private_key: The private key to import.
:param pin_policy: The PIN policy.
:param touch_policy: The touch policy.
Fr   zRSA exponent must be 65537zImporting key with pin_policy=, touch_policy=zPrivate key imported in slot rv  )$rq   r:   ra   r   r  rR   rJ   r/   r6   Zprivate_numbersr   r   r   r    r$   ZpZqZdmp1Zdmq1ZiqmprM   rN   Zprivate_bytesr   r{  r   r   Zprivate_valueTAG_PIN_POLICYTAG_TOUCH_POLICYr
  r  r  r  INS_IMPORT_KEYr(  )	r@   r   r  r   r   rn   r   Znumbersr   s	   &&&&&    r9   put_keyZPivSession.put_key9  s(     Dz++K,B,B,DEx\5I".!113GG%%''50'(DEE1HBD)GIIr23dIgii456dIgllB789 dIgllB789 dIgllB78	9  (**HOO<< H$4$44$))LL-"3"3\^D "113GGtYw'<'<bABDC	*(=>>DC()L*ABBD,ZL~V	
 	>84H3D68*MNr8   c          
     r  )rD   r   rq   rn   r:   r   r   r   r   rE   r-   r0   rF   rG   r9   rH   r  s  sC      P  P P  P 	 P
 # P 
 Pr8   c           
     s.   \        V4      p\        V4      pV P                  W#VR4       \        \        \        V4      4      pV'       d!   V\        \        \        V4      4      ,          pV'       d!   V\        \        \        V4      4      ,          p\        P                  RV RV 24       V P                  P                  ^ \        ^ V\        ^V4      4      p\        P                  RV RV 24       \        V\        P                  ! RV4      4      # )zGenerate private key in slot.

Requires authentication with management key.

:param slot: The slot to generate the private key in.
:param key_type: The key type.
:param pin_policy: The PIN policy.
:param touch_policy: The touch policy.
TzGenerating key with pin_policy=r  zPrivate key generated in slot rv  iI  )rq   r:   r  r    TAG_GEN_ALGORITHMr$   r  r  r
  r  r  r  INS_GENERATE_ASYMMETRICr(  r   r5  )r@   r   rn   r   r   r   r+     &&&&&  r9   generate_keyZPivSession.generate_keys  s      DzH%x\4H+Yx-@AC	*(=>>DC()L*ABBD-j\W	
 ==**&4T4
 	4TF)H:NO'#**VX2NOOr8   c               rS   r  r0   rF   rG   r9   rH   r    s     
K 
Kt 
K(8 
Kr8   c                s    \        V P                  R4       \        V4      pV P                  P	                  ^ \
        V^ 4      p\        P                  RV 24       \        P                  ! V\        4       4      # )zkAttest key in slot.

:param slot: The slot where the key has been generated.
:return: A X.509 certificate.
zAttested key in slot r  )r%   r   rq   r  r  
INS_ATTESTr
  r  r   r  r   )r@   r   r+  r`   r9   
attest_keyZPivSession.attest_key  s_     	i0Dz==**1j$B,TF34--h8IJJr8   c               rD  )rD   r   rq   to_slotrE   r   r0   rF   rG   r9   rH   r    s&     E E$ E E$ Er8   c                s   \        V P                  R4       \        V4      p\        V4      p\        P	                  RV RV 24       V P
                  P                  ^ \        W!4       \        P                  RV RV 24       R# )zMove key from one slot to another.

Requires authentication with management key.

:param from_slot: The slot containing the key to move.
:param to_slot: The new slot to move the key to.
zMoving key from slot z to zKey moved from slot Nr  	r%   r   rq   r
  r  r  r  INS_MOVE_KEYr(  )r@   r   r  r  r9   move_keyZPivSession.move_key  sn     	i0O	w-,YKtG9EF<D*9+T'CDr8   c               rS   r  r0   rF   rG   r9   rH   r    s     3 3t 3 3r8   c                s    \        V P                  R4       \        V4      p\        P	                  RV 24       V P
                  P                  ^ \        ^V4       \        P                  RV 24       R# )z{Delete a key in a slot.

Requires authentication with management key.

:param slot: The slot containing the key to delete.
zDeleting key in slot zKey deleted in slot Nr  r  r  r   r9   
delete_keyZPivSession.delete_key  s[     	i0Dz,TF34<t<*4&12r8   c           
     	s
    V P                   P                  ^ V^ V\        V4      \        V4      ,           4       R#   \         d<   p\	        TP
                  4      pTf   h T\        8X  d   Y`n        \        T4      hRp?ii ; ir    N)	r  r  r   r(   r   r   r&  r  r   )r@   Zinsp2Zvalue1Zvalue2r   rB  r  r9   r$  ZPivSession._change_reference  ss    
	+MM##32z&1Jv4FF  	+&qtt,GV|,3)!'**	+s   8< B6A==Bc                	s   \        V P                  R4       \        P                  ! V P                  P                  ^ \        ^ V4      4      pV\        ,          p\        V\        ,          R8g  V\        ,          V\        ,          4      # )r  r   rg  )r%   r   r    r   r  r  rh  rt  r   rk  INDEX_RETRIES_TOTALINDEX_RETRIES_REMAINING)r@   r  r   ZattemptsrC  r9   re  Z PivSession._get_pin_puk_metadata  sl    i0~~dmm55a9I1bQR,-()U2(),-
 	
r8   c                	s    V P                   P                  ^ \        TT\        \        \        \
        4      \        V'       d   \        M\        V4      ,           4      4      p\        P                  ! \
        \        P                  ! \        V4      4      #   \         d(   pTP                  \        P                  8X  d   Thh Rp?ii ; ir  )r  r  r1  r    r3  r9  TAG_AUTH_EXPONENTIATIONr8  r5  r(   r   r'   ZINCORRECT_PARAMETERS)r@   r   rn   r   Zexponentiationr+  r   r  r9   rw  ZPivSession._use_private_key  s    	}}..  )*  . 4!3H$ ::!

    	ttr...	s   BB C	""CC	c               s0    V ^8  d   QhRRRRRRRRR	RR
R/# )rD   rn   r:   r   r   r   r   r   r   r  rE   r   r0   rF   rG   r9   rH   r    sF     $ $$ $ #	$
 $  $ 
$r8   c                s    \        V P                  VVVVV4       V\        P                  \        P                  39   d   V P                  4        R# R# )aq  Check if a key type is supported by this YubiKey.

This method will return None if the key (with PIN and touch policies) is
supported, or it will raise a NotSupportedError if it is not.

Set the generate parameter to True to check if generating the key is supported
(in addition to importing).

Set fips_restrictions to True to apply restrictions based on FIPS status.
N)r  r   r   r   r   r   )r@   rn   r   r   r   r  r  r9   r  ZPivSession.check_key_support  sO    & 	LL	
 *//1H1HII!!# Jr8   )r  r  r  r  r  r<   )F)FF)0r1   r2   r3   r4   r   r  re   r   r  r)  r,  r   r.  r?  r"  rJ  rM  r!  rS  rZ  r]  ra  rN  r#  r  rr  r   r   r   r|  r  r  r  r  r  r   r   r   r  r  r  r  r  r$  re  rw  r  r7   r0   r8   r9   r  r    s:   -J2  
 ) )3<j# > > 8Ct*<+&(3T,&#$(.2
2


$
0D6/.A:?6E"=2S:	3 ",!3!3%1%9%98| ",!3!3%1%9%9 PD
KE3+
@$ $r8   r  s   )r   )	r   r   r   r   r   r   r   r   r   r   )TF)__conditional_annotations__Z
__future__r   r  Zloggingr6  rO   r   r  Zbase64r   Zdataclassesr   r   Zdatetimer   Zenumr   r   r   Ztypingr	   r
   r   Zcryptographyr   Zcryptography.hazmat.backendsr   Zcryptography.hazmat.primitivesr   Z)cryptography.hazmat.primitives.asymmetricr   r   r   r   Z1cryptography.hazmat.primitives.asymmetric.paddingr   Z/cryptography.hazmat.primitives.asymmetric.utilsr   Z&cryptography.hazmat.primitives.ciphersr   r   r   Z,cryptography.hazmat.primitives.constant_timer   Z,cryptography.hazmat.primitives.serializationr   r   r   r   Zcorer   r   r   r    r!   r"   r#   r$   r%   Zcore.smartcardr&   r'   r(   r)   r*   r+   Z/cryptography.hazmat.primitives.asymmetric.typesr,   Z	getLoggerr1   r
  rV   rY   r]   r^   r-   r   ZRSAPrivateKeyWithSerializationZ(EllipticCurvePrivateKeyWithSerializationZEd25519PrivateKeyZX25519PrivateKeyr.   rr   r/   r:   rg   rp   r2  rH  rq   r   r   r   ZDEFAULT_MANAGEMENT_KEYr   rL  r@  rR  r%  r  r1  r  r  r  rh  r*  r  r`  r'  r  r  r>  r4  r8  r9  r  r  r  r  r  r  r3  r   r  r  rj  ri  ro  rq  rk  rt  rs  ru  rp  ZORIGIN_IMPORTEDrn  rl  r  r  r&  rW  ZUV_P2r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r  r  r  )r  s   @r9   <module>r     s  8 # "   	 	    *  & & 5 5  8 1 N N O E L L A 
 
 
  N 
		8	$    
9  &&112   I  T  
 ,Hw ,H ,H^ '  (	.   07 0 0B (- (- (-V    7  *    
    
 	      

        " !      		'       	P 	P 	P   ? 
		* ;F ;F ;F| 48
 8
 8
vQ0-Q*&YRQ.   !?HJ$ J$r8   