HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //lib/python3.9/site-packages/yubico/__pycache__/yubico_util.cpython-39.opt-1.pyc
a

�w\z�@s�dZgd�ZddlZddlZddlmZddlmZddlmZdZ	d	d
�Z
dd�Zd
d�Zdd�Z
Gdd�d�Zd dd�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)�sys�version_info�ord�int)Zbyte�r�6/usr/lib/python3.9/site-packages/yubico/yubico_util.py�ord_bytes
rcCs tjdkrt|�St|g�SdS)z1Convert an integer value to a length-1 bytestringrN)r
r�chr�bytes)Znumberrrr�chr_byte#s
rcCsHd}|D]:}|t|�N}td�D] }|d@}|dL}|r |dN}q q|S)zN
    Calculate an ISO13239 CRC checksum of the input buffer (bytestring).
    i���ri�)r�range)�dataZm_crc�this�_�jrrrr*srcCs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)rrrrr8src@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||jvr|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 FNr)r$rrr�disable[szDumpColors.disableN)�__name__�
__module__�__qualname__�__doc__r&r(r*r+rrrrrAs
rrFc
Cs|st|�St|�tur*t�dt|���d}d}t||�D]�}|r�|d|dd�}}t�}|�d�}t|�t	j
@r�|�d�}nt|�t	j@r�|�d�}|d	�d
d�|D��|�d�}	|	dt|�7}	nd	�d
d�|D��}	|d||	f7}||7}q<|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'���Nr!rr � cSsg|]}dt|��qS�z%02x�r��.0�xrrr�
<listcomp>t�zhexdump.<locals>.<listcomp>z %02xcSsg|]}dt|��qSr2r3r4rrrr7wr8z
%04X   %s
)
�str�typerr
Z
InputError�grouprr(rr	ZRESP_PENDING_FLAGZSLOT_WRITE_FLAG�join)
�src�lengthZcolorize�offset�resultrZlastr"ZcolorZhex_srrrr_s*

"
rcs ��fdd�tdt����D�S)z* Split data into chunks of num chars each csg|]}�||���qSrr)r5�i�rZnumrrr7~r8zgroup.<locals>.<listcomp>r)r�lenrBrrBrr;|sr;cCs8z
tj}Wnty"tj}Yn0|dd�}|�|�S)z. Convert a modhex bytestring to ordinary hex. scbdefghijklnrtuvs0123456789abcdef)�string�	maketrans�AttributeErrorr�	translate)rrEZt_maprrrr�s

r�cCs�t|�dkrt�d��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�
)rCr
ZYubicoErrorr)Zhmac_resultr>r?Zbin_coderrrr�s
���rcCsTi}|rPt|d�t|d�|dd�}}}|d|�||d�||<}q|S)zE Parses a bytestring of TLV values into a dict with the tags as keys.rrrPNr3)r�parsed�t�lrrr�	tlv_parse�s
( rU)rF)rH)r/�__all__r
rDZyubico_versionrr'r	r
rrrrrrrr;rrrUrrrr�<module>s"