o
    6h                     @   s  d Z ddlZddlZddlZddlmZ dd Zejdk rdddlZdd Z	d	d
 Z
ejdk s9ejdk s9e dkrFdd Zdd Zdd Zndd Zdd Zdd Zdd Zdd Zdd Zd)ddZn d d
 Z
d!d Z	d"d Zd#d Zd$d ZejZd%d Zd)d&dZd'd( ZdS )*zD
Common functions for providing cross-python version compatibility.
    N)integer_typesc                 C   s   | | }t |tr|S t|S )z1Take index'th byte from string, return as integer)
isinstancer   ord)stringindexval r   a/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/ecdsa/_compat.pystr_idx_as_int
   s   
r
   )   r   c                 C      t | S )#Cast the input into array of bytes.)bufferbuffer_objectr   r   r	   normalise_bytes   s   r   c                 C      | S Nr   )retr   r   r	   hmac_compat      r   )      )r   r      Javac                 C   s   t dd| S ),Removes all whitespace from passed in string\s+ )resubtextr   r   r	   remove_whitespace#      r"   c                 C   r   r   )strr   r   r   r	   compat26_str'   s   r&   c                 C   s   | dkrdS t t| d S )Nr   r   )lenbinr%   r   r   r	   
bit_length*   s   r)   c                 C      t jdd| t jdS r   r   r   )flagsr   r   UNICODEr    r   r   r	   r"   1      c                 C   r   r   r   r%   r   r   r	   r&   5   r   c                 C      |   S z8Return number of bits necessary to represent an integer.r)   r%   r   r   r	   r)   8      c                 C   s   t t| S r   )binasciib2a_hexr&   r%   r   r   r	   r5   <   s   r5   c              
   C   s6   zt t| W S  ty } ztd| d }~ww )Nbase16 error: %s	bytearrayr4   a2b_hex	Exception
ValueErrorr   er   r   r	   r9   ?   s   r9   c                 C   sF   | sdS |dkrt t| dS |dkrt t| ddd dS td)zConvert bytes to an int.r   big   littleNz(Only 'big' and 'little' endian supported)intr5   r;   )r   	byteorderr   r   r	   bytes_to_intE   s   rD   r>   c                    sp   |du rt  }|dkrt fddttd|d dD S |dkr4t fddtd|d dD S td	)
z Return number converted to bytesNr>   c                 3       | ]	} |? d @ V  qdS    Nr   .0ir%   r   r	   	<genexpr>T       
zint_to_bytes.<locals>.<genexpr>r      r@   c                 3   rE   rF   r   rH   r%   r   r	   rK   X   rL   z'Only 'big' or 'little' endian supported)byte_lengthr8   reversedranger;   r   lengthrC   r   r%   r	   int_to_bytesO   s   rS   c                 C   r   r   r   )datar   r   r	   r   _   r   c                 C   s   t | dS )r   B)
memoryviewcastr   r   r   r	   r   b   r#   c                 C   r   r   r   r%   r   r   r	   r&   f   r   c                 C   r*   r+   r-   r    r   r   r	   r"   i   r/   c              
   C   s<   zt tt | dW S  ty } ztd| d }~ww )Nasciir6   r7   r<   r   r   r	   r9   m   s   c                 C   r0   r1   r2   r%   r   r   r	   r)   y   r3   c                 C   s4   |du rt | }t| tst| } t| j||dS )zConvert integer to bytes.N)rR   rC   )rN   r   rB   r8   to_bytesrQ   r   r   r	   rS   }   s
   
c                 C   s   t | }|d d S )z9Return number of bytes necessary to represent an integer.r   rM   r2   )r   rR   r   r   r	   rN      s   rN   )Nr>   )__doc__sysr   r4   sixr   r
   version_infoplatformr   r   systemr"   r&   r)   r5   r9   rD   rS   rB   
from_bytesrN   r   r   r   r	   <module>   s@    




	

