HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/yubico/__pycache__/yubico_util.cpython-36.pyc
3

y@�Vz�@s�dZdddddgZddlZddlZdd	lmZdd
lmZddlmZdZ	d
d�Z
dd�Zdd�Zdd�Z
Gdd�d�Zddd�Zdd�Zdd�Zd dd�Zdd�ZdS)!z&
utility functions for Yubico modules
�crc16�validate_crc16�hexdump�
modhex_decode�
hotp_truncate�N�)�__version__)�yubikey_defs)�yubico_exceptioni��cCstjdkrt|�St|�SdS)z#Convert a byte to its integer value�rN)rr)�sys�version_info�ord�int)Zbyte�r�!/usr/lib/python3.6/yubico_util.py�ord_bytes
rcCs tjdkrt|�St|g�SdS)z1Convert an integer value to a length-1 bytestringrrN)rr)rr
�chr�bytes)Znumberrrr�chr_byte#s
rcCsPd}xF|D]>}|t|�N}x,td�D] }|d@}|dL}|r$|dN}q$Wq
W|S)zN
    Calculate an ISO13239 CRC checksum of the input buffer (bytestring).
    i���ri�)r�range)�dataZm_crc�this�_�jrrrr*s
cCst|�tkS)zs
    Validate that the CRC of the contents of buffer is the residual OK value.

    The input is a bytestring.
    )r�_CRC_OK_RESIDUAL)rrrrr8sc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
DumpColorsz> Class holding ANSI colors for colorization of hexdump output cCsdddd�|_d|_dS)Nzzz)�BLUE�GREEN�RESETT)�colors�enabled)�selfrrr�__init__Ds

zDumpColors.__init__cCs|jr||jkr|j|SdS)ze
        Get the ANSI code for 'what'

        Returns an empty string if disabled/not found
        �)r"r!)r#Zwhatrrr�getLs

zDumpColors.getcCs
d|_dS)z Enable colorization TN)r")r#rrr�enableWszDumpColors.enablecCs
d|_dS)z Disable colorization FN)r")r#rrr�disable[szDumpColors.disableN)�__name__�
__module__�__qualname__�__doc__r$r&r'r(rrrrrAs
rrFc
Cs|st|�St|�tk	r*tjdt|���d}d}x�t||�D]�}|r�|d|dd�}}t�}|jd�}t|�t	j
@r�|jd�}nt|�t	j@r�|jd�}|d	jd
d�|D��|jd�}	|	dt|�7}	nd	jd
d�|D��}	|d||	f7}||7}q>W|S)zd Produce a string hexdump of src, for debug output.

    Input: bytestring; output: text string
    z)Hexdump 'src' must be bytestring (got %s)rr%rNr rr� cSsg|]}dt|��qS)z%02x)r)�.0�xrrr�
<listcomp>tszhexdump.<locals>.<listcomp>z %02xcSsg|]}dt|��qS)z%02x)r)r.r/rrrr0wsz
%04X   %s
���r1)
�str�typerr
Z
InputError�grouprr&rr	ZRESP_PENDING_FLAGZSLOT_WRITE_FLAG�join)
�src�lengthZcolorize�offset�resultrZlastr!ZcolorZhex_srrrr_s*

"cs ��fdd�tdt����D�S)z* Split data into chunks of num chars each csg|]}�||���qSrr)r.�i)r�numrrr0~szgroup.<locals>.<listcomp>r)r�len)rr;r)rr;rr4|sr4cCs:y
tj}Wntk
r$tj}YnX|dd�}|j|�S)z. Convert a modhex bytestring to ordinary hex. scbdefghijklnrtuvs0123456789abcdef)�string�	maketrans�AttributeErrorr�	translate)rr>Zt_maprrrr�s

�cCs�t|�dkrtjd��t|d�d@}t||�d@d>t||d�d@d	>Bt||d
�d@d>Bt||d�d@B}|d
|S)zH Perform the HOTP Algorithm truncating.

    Input is a bytestring.
    �zHMAC-SHA-1 not 20 bytes long����r���rr�
)r<r
ZYubicoErrorr)Zhmac_resultr7r8Zbin_coderrrr�s

XcCsXi}xN|rRt|d�t|d�|dd�}}}|d|�||d�||<}qW|S)zE Parses a bytestring of TLV values into a dict with the tags as keys.rrrIN)r)rZparsed�t�lrrr�	tlv_parse�s
("rM)rF)rA)r,�__all__rr=Zyubico_versionrr%r	r
rrrrrrrr4rrrMrrrr�<module>s*