+
     h	)  c                  sN    R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHt  ! R R4      tR# )a  ATR class managing some of the Answer To Reset content.

__author__ = "https://www.gemalto.com/"

Copyright 2001-2012 gemalto
Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com

This file is part of pyscard.

pyscard is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

pyscard is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with pyscard; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
)annotationsN)SmartcardExceptionc                  s   ] tR t^"t$ Rt. R:OtR]R&   . R;OtR]R&   . R<OtR]R&   R R lt	]
R R	 l4       t]
R
 R l4       t]
R R l4       t]
R R l4       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R& R' ltR( R) ltR* R+ ltR, R- ltR. R/ ltR0 R1 ltR2 R3 lt R4 R5 lt!R6 R7 lt"R8t#R9# )=ATRzpParse and represent Answer to Reset sequences.

Answer to Reset sequences are defined in ISO 7816-3, section 8.
zlist[int | str]clockrateconversionbitratefactorcurrenttablec               s     V ^8  d   QhRRRR/# )   atr	list[int]returnNone Zformat   "4/usr/lib64/python3.14/site-packages/smartcard/ATR.py__annotate__ATR.__annotate__N   s     f fI f$ f    c                s,	   \        V4      ^8  d   \        R4      hV^ ,          R9  d   \        RV^ ,          R 24      hWn        V P                  ^ ,          V n        V P                  ^,          V n        V P                  ^,          V n        . V n        . V n        . V n        . V n	        . V n
        V P                  p^pVEe   V P                  P                  V^,	          ^,          4       V ;P                  R.,          un        V ;P                  R.,          un        V ;P                  R.,          un        V ;P                  R.,          un	        V P                  R,          ^,          '       d*   V^,          pV P                  V,          V P                  R&   V P                  R,          ^,          '       d*   V^,          pV P                  V,          V P                  R&   V P                  R,          ^,          '       d*   V^,          pV P                  V,          V P                  R&   V P                  R,          ^,          '       d*   V^,          pV P                  V,          V P                  R&   V P                  R,          pEK  V^,
          V n        V P                  V^,           V^,           V P
                  ,            V n        RV n        RV n        \        V P                  4      V^,           V P
                  ,           ^,           8H  V n        V P                   '       dW   V P                  R,          V n        \"        P$                  ! \&        P(                  V P                  R,          4      ^ 8H  V n        RV n        V P                  ^ ,          e'   V P                  ^ ,          ^,	          ^,          V n        RV n        V P                  ^ ,          e    V P                  ^ ,          ^,          V n        RV n        V P                  ^ ,          e'   V P                  ^ ,          ^,	          ^,          V n        RV n        V P                  ^ ,          e    V P                  ^ ,          ^,          V n        V P                  ^ ,          V n        R# )a:  Parse ATR and initialize members:

  - TS: initial character
  - T0: format character
  - TA[n], TB[n], TC[n], TD[n], for n=0,1,...: protocol parameters

@note: protocol parameters indices start at 0, e.g.
TA[0], TA[1] correspond to the ISO standard TA1, TA2
parameters

  - historicalBytes: the ATR T1, T2, ..., TK historical bytes
  - TCK: checksum byte (only for protocols different from T=0)
  - FI: clock rate conversion factor
  - DI: voltage adjustment factor
  - PI1: programming voltage factor
  - II: maximum programming current factor
  - N: extra guard time
z+ATR sequences must be at least 2 bytes longzinvalid TS 0xZ02xN:   NN>   i;   i?   i)lenr   r   TST0KTATBTCTDYappendinterfaceBytesCounthistoricalBytesTCK
checksumOKhasChecksum	functoolsZreduceoperatorZxorFIDIIIPI1N)selfr   tdZoffsets   &&  r   __init__ZATR.__init__N   sJ   ( s8a<$'RTTq6%$}SVCL%ABB ((1+ ((1+ 4 %'$&$&$&nFFMM"'D.)GGvGGGvGGGvGGGvGvvbzD  !"hhv.vvbzD  !"hhv.vvbzD  !"hhv.vvbzD  !"hhv.B#)A:   $xx
VaZ$&&5HI  $'+txx=FQJ,?!,CCxx|DH'..x||TXXb\JaODO #771:!ggajAo,DG #771:!ggaj4'DG #771:!ggajAo,DG  $771:!wwqzD(DH r   c                   V ^8  d   QhRR/# r   r	   z
list[bool]r   r   r   r   r   r           2 2z 2r   c                |    \         P                  ! R\        4       V P                   Uu. uF  qRJNK  	  up# u upi )z7Deprecated. Replace usage with `ATR.TA[i] is not None`.z*Replace usage with `ATR.TA[i] is not None`N)warningswarnDeprecationWarningr   )r)   ta   & r   hasTAZ	ATR.hasTA   2     	BDVW)-12$111   9c               r,   r-   r   r   r   r   r   r      r.   r   c                r/   )z7Deprecated. Replace usage with `ATR.TB[i] is not None`.z*Replace usage with `ATR.TB[i] is not None`N)r0   r1   r2   r   )r)   tbr4   r   hasTBZ	ATR.hasTB   r6   r7   c               r,   r-   r   r   r   r   r   r      r.   r   c                r/   )z7Deprecated. Replace usage with `ATR.TC[i] is not None`.z*Replace usage with `ATR.TC[i] is not None`N)r0   r1   r2   r   )r)   tcr4   r   hasTCZ	ATR.hasTC   r6   r7   c               r,   r-   r   r   r   r   r   r      r.   r   c                r/   )z7Deprecated. Replace usage with `ATR.TD[i] is not None`.z*Replace usage with `ATR.TD[i] is not None`N)r0   r1   r2   r   )r)   r*   r4   r   hasTDZ	ATR.hasTD   r6   r7   c               r,   r   r	   z
int | Noner   r   r   r   r   r      s      Z r   c                    V P                   # )zCReturn the checksum of the ATR. Checksum is mandatory only
for T=1.)r   r)      &r   getChecksumZATR.getChecksum   s     xxr   c               r,   )r   r	   r   r   r   r   r   r   r      s     $ $I $r   c                r>   )zReturn historical bytes.)r   r?   r@   r   getHistoricalBytesZATR.getHistoricalBytes   s    ###r   c               r,   r   r	   Zintr   r   r   r   r   r      s     ) ) )r   c                s,    \        V P                  4      # )z!Return count of historical bytes.)r   r   r?   r@   r   getHistoricalBytesCountZATR.getHistoricalBytesCount   s    4''((r   c               r,   rC   r   r   r   r   r   r      s     ( ( (r   c                r>   )z Return count of interface bytes.)r   r?   r@   r   getInterfaceBytesCountZATR.getInterfaceBytesCount   s    '''r   c               r,   r=   r   r   r   r   r   r            
 r   c                (    V P                   ^ ,          # )zReturn TA1 byte.)r   r?   r@   r   getTA1Z
ATR.getTA1       wwqzr   c               r,   r=   r   r   r   r   r   r      rF   r   c                rG   )zReturn TB1 byte.)r   r?   r@   r   getTB1Z
ATR.getTB1   rI   r   c               r,   r=   r   r   r   r   r   r      rF   r   c                rG   )zReturn TC1 byte.)r   r?   r@   r   getTC1Z
ATR.getTC1   rI   r   c               r,   r=   r   r   r   r   r   r      rF   r   c                rG   )zReturn TD1 byte.r   r?   r@   r   getTD1Z
ATR.getTD1   rI   r   c               r,   r   r	   z	int | strr   r   r   r   r   r      s      ) r   c                sd    V P                   e"   \        P                  V P                   ,          # ^# )zReturn bit rate factor.)r%   r   r   r?   r@   r   getBitRateFactorZATR.getBitRateFactor   s$    77$$TWW--r   c               r,   rN   r   r   r   r   r   r      s      	 r   c                sd    V P                   e"   \        P                  V P                   ,          # R# )zReturn clock rate conversion.t  )r$   r   r   r?   r@   r   getClockRateConversionZATR.getClockRateConversion   s$    77**47733r   c               r,   rN   r   r   r   r   r   r      s      y r   c                sd    V P                   e"   \        P                  V P                   ,          # ^2# )z#Return maximum programming current.)r&   r   r   r?   r@   r   getProgrammingCurrentZATR.getProgrammingCurrent   s$    77##DGG,,r   c               r,   rC   r   r   r   r   r   r     s      s r   c                sV    V P                   e   ^^V P                   ,           ,          # ^# )zReturn programming voltage.)r'   r?   r@   r   getProgrammingVoltageZATR.getProgrammingVoltage  s"    88DHH%%r   c               r,   r=   r   r   r   r   r   r     s      j r   c                r>   )zReturn extra guard time.)r(   r?   r@   r   getGuardTimeZATR.getGuardTime  s    vvr   c               r,   )r   r	   zdict[str, bool]r   r   r   r   r   r     s       r   c                s    / pV P                    F  pVf   K	  RVRV^,           2&   K  	  V P                   ^ ,          f   RVR&   V# )z,Returns a dictionary of supported protocols.TzT=T=0rL   )r)   Z	protocolsr*   s   &  r   getSupportedProtocolsZATR.getSupportedProtocols  sO    %'	''B~.2	BrDyk*+  771:#Ier   c               r,   r   r	   Zboolr   r   r   r   r   r          5 5t 5r   c                (    RV P                  4       9   # )z Return True if T=0 is supported.rU   rV   r?   r@   r   isT0SupportedZATR.isT0Supported      22444r   c               r,   rW   r   r   r   r   r   r     rX   r   c                rY   )z Return True if T=1 is supported.zT=1rZ   r?   r@   r   isT1SupportedZATR.isT1Supported  r\   r   c               r,   rW   r   r   r   r   r   r   !  s     6 6 6r   c                rY   )z!Return True if T=15 is supported.zT=15rZ   r?   r@   r   isT15SupportedZATR.isT15Supported!  s    33555r   c               r,   r   r	   Zstrr   r   r   r   r   r   %  s          r   c                s   . p\        \        V P                  V P                  V P                  V P
                  4      ^4      pV F{  w  pw  rErgVe   VP                  RV RVR 24       Ve   VP                  RV RVR 24       Ve   VP                  RV RVR 24       Vf   Kc  VP                  RV RVR 24       K}  	  VP                  RRP                  V P                  4       4       24       VP                  R	V P                  4        24       VP                  R
V P                  4        24       V P                  4       e#   VP                  RV P                  4        24       VP                  RV P                  4        24       VP                  RV P                  4        24       VP                  RV P                  4        24       VP                  RV P                  4        24       VP                  RV P!                  4        24       VP                  RV P#                  4        24       VP                  RV P%                  4        24       RP                  V4      # )z$Render the ATR to a readable format.r   z: Zxr   r   r   zsupported protocols Z,zT=0 supported: zT=1 supported: z
checksum: z	clock rate conversion factor: z	bit rate adjustment factor: z	maximum programming current: z	programming voltage: z	guard time: znb of interface bytes: znb of historical bytes: Z
)Z	enumerateZzipr   r   r   r   r   ZjoinrV   r[   r]   rA   rQ   rO   rR   rS   rT   rE   rD   )r)   ZlinesZenumerated_tx_valuesZir3   r8   r:   r*   s   &       r   renderZ
ATR.render%  s5    (TWWdggtww)PRST#7A~r!Br!f-.~r!Br!f-.~r!Br!f-.~r!Br!f-. $8 	+CHHT5O5O5Q,R+STUt'9'9';&<=>t'9'9';&<=>)LL:d&6&6&8%9:;78S8S8U7VWX5d6K6K6M5NOP6t7Q7Q7S6TUV.t/I/I/K.LMN~d&7&7&9%:;<.t/J/J/L.MNO/0L0L0N/OPQyyr   c               r,   )r   r	   r
   r   r   r   r   r   r   E  s      d r   c                sn    \         P                  ! R\        4       \        V P	                  4       4       R# )z4Deprecated. Replace usage with `print(ATR.render())`z(Replace usage with `print(ATR.render())`N)r0   r1   r2   Zprintr`   r?   r@   r   dumpZATR.dumpE  s"     	@BTUdkkmr   c               r,   r_   r   r   r   r   r   r   K  s     0 0 0r   c                sf    \        V P                  4      P                  R4      P                  4       # )zJRender the ATR as a space-separated string of uppercase hexadecimal pairs.Z )Zbytesr   ZhexZupperr?   r@   r   __str__ZATR.__str__K  s&     TXX""3'--//r   )r%   r$   r&   r   r(   r'   r   r   r   r   r   r   r   r   r   r    r!   r   r   N)rP   rP   i.  i  i\  i  iD  RFUrc   i   i   i   i   i   rc   rc   )rc   r   r   i   i   i   i    i@   i   i   rc   rc   rc   rc   rc   rc   )i   i2   id   rc   )$Z__name__Z
__module__Z__qualname__Z__firstlineno____doc__r   Z__annotations__r   r   r+   Zpropertyr5   r9   r;   r<   rA   rB   rD   rE   rH   rJ   rK   rM   rO   rQ   rR   rS   rT   rV   r[   r]   r^   r`   ra   rb   Z__static_attributes__r   r   r   r   r   "   s    
, $&M? $ %9L/8fP 2 2 2 2 2 2 2 2
$)(556 @0 0r   r   )	rd   Z
__future__r    r"   r#   r0   Zsmartcard.Exceptionsr   r   r   r   r   <module>re      s'   0 #    3l0 l0r   