o
    /׾g                     @   s  d Z g dZddlZddlZddlZddlmZmZ ddlZG dd de	Z
e
ejZe
ejZdd Zd	d
 Zdd Zdd ZdZz
ddlmZmZ W n eya   ddlZdd Zdd ZY n	w dd Zdd ZejZejZdd Zdd ZdddZdd ZdS ) a,  Module containing a cryptographic-quality source of randomness and
other cryptographically useful functionality

Python 2.4 needs no external support for this module, nor does Python
2.3 on a system with /dev/urandom.

Other configurations will need a quality source of random bytes and
access to a function that will convert binary strings to long
integers. This module will work with the Python Cryptography Toolkit
(pycrypto) if it is present. pycrypto can be found with a search
engine, but is currently found at:

http://www.amk.ca/python/code/crypto
)
base64ToLongbinaryToLonghmacSha1
hmacSha256longToBase64longToBinaryrandomString	randrangesha1sha256    N)toBase64
fromBase64c                   @   s   e Zd Zdd ZdS )HashContainerc                 C   s   || _ | j| _d S N)newdigest_size)selfhash_constructor r   Z/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/openid/cryptutil.py__init__'   s   zHashContainer.__init__N)__name__
__module____qualname__r   r   r   r   r   r   &   s    r   c                 C   >   t | trt| dd} t |trt|dd}t| |t S Nutf-8)encoding)
isinstancestrbyteshmacr   sha1_moduledigestkeytextr   r   r   r   0   
   

r   c                 C   $   t | trt| dd} t|  S r   )r   r   r    r"   r   r#   sr   r   r   r	   8      
r	   c                 C   r   r   )r   r   r    r!   r   sha256_moduler#   r$   r   r   r   r   >   r'   r   c                 C   r(   r   )r   r   r    r,   r   r#   r)   r   r   r   r
   F   r+   r
   T)long_to_bytesbytes_to_longc                 C   s*   | dkrdS t t| }|  t|S )Nr       )	bytearraypickleencode_longreverser    )lbr   r   r   r   V   s
   r   c                 C   s2   t | tr
| d} t| }|  tt|S )Nr   )r   r   encoder0   r3   r1   decode_longr    )r*   r5   r   r   r   r   ]   s
   

r   c                 C   s0   | dk rt dt| }|d dkrd| S |S )Nr   -This function only supports positive integers   r/   )
ValueErrorr-   )r4   
bytestringr   r   r   r   f   s   c                 C   s(   | st d| d dkrt dt| S )Nz Empty string passed to strToLongr   r9   r8   )r:   r.   )r;   r   r   r   r   p   s
   c                 C      t t| S r   )r   r   )r4   r   r   r   r         r   c                 C   r<   r   )r   r   r)   r   r   r   r      r=   r   c                    s6    du rt | S t d fddt| D S )z:Produce a string of length random bytes, chosen from chrs.N c                    s   g | ]} t  qS r   )r   ).0_chrsnr   r   
<listcomp>   s    z randomString.<locals>.<listcomp>)getByteslenjoinrange)lengthrB   r   rA   r   r      s   r   c                 C   sB   t | t |kr
dS d}tt | D ]}|o| | || k}q|S )NFT)rF   rH   )s1s2resultir   r   r   const_eq   s   rN   r   ) __doc____all__r!   osrandomopenid.oidutilr   r   hashlibobjectr   r	   r"   r
   r,   r   r   SHA256_AVAILABLECrypto.Util.numberr-   r.   ImportErrorr1   r   r   urandomrE   r   r   r   r   rN   r   r   r   r   <module>   s<    



	