File: //lib/python3.9/site-packages/yubico/__pycache__/yubico_util.cpython-39.pyc
a
�w\z � @ s� d Z g d�ZddlZddlZddlmZ ddlmZ ddlmZ dZ d d
� Z
dd� Zd
d� Zdd� Z
G dd� 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�� c C s t jdk rt| �S t| �S dS )z#Convert a byte to its integer value�� r N)�sys�version_info�ord�int)Zbyte� r �6/usr/lib/python3.9/site-packages/yubico/yubico_util.py�ord_byte s
r c C s t jdk rt| �S t| g�S dS )z1Convert an integer value to a length-1 bytestringr N)r
r �chr�bytes)Znumberr r r �chr_byte# s
r c C sH d}| D ]:}|t |�N }td�D ] }|d@ }|dL }|r |dN }q q|S )zN
Calculate an ISO13239 CRC checksum of the input buffer (bytestring).
i�� � r i� )r �range)�dataZm_crc�this�_�jr r r r * s r c C s 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)r r r r r 8 s r c @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
S )�
DumpColorsz> Class holding ANSI colors for colorization of hexdump output c C s dddd�| _ d| _d S )Nz[94mz[92mz[0m)�BLUE�GREEN�RESETT)�colors�enabled��selfr r r �__init__D s �zDumpColors.__init__c C s | j r|| jv r| j| S dS )ze
Get the ANSI code for 'what'
Returns an empty string if disabled/not found
� )r# r"