a
    xd                     @   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y   ddlZdd Zdd ZY n0 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)selfZhash_constructor r   H/var/www/html/Ranjet/env/lib/python3.9/site-packages/openid/cryptutil.py__init__'   s    zHashContainer.__init__N)__name__
__module____qualname__r   r   r   r   r   r   &   s   r   c                 C   s>   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   s
    

r   c                 C   s$   t | trt| dd} t|  S r   )r   r   r   r    r   r!   sr   r   r   r	   8   s    
r	   c                 C   s>   t | trt| dd} t |tr,t|dd}t| |t S r   )r   r   r   r   r   sha256_moduler!   r"   r   r   r   r   >   s
    

r   c                 C   s$   t | trt| dd} t|  S r   )r   r   r   r'   r   r!   r%   r   r   r   r
   F   s    
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   encoder+   r.   r,   decode_longr   )r&   r0   r   r   r   r   ]   s
    

r   c                 C   s4   | dk rt dt| }|d dkr,d| S |S d S )Nr   -This function only supports positive integers   r*   )
ValueErrorr(   )r/   
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   r4   r3   )r5   r)   )r6   r   r   r   r   p   s
    c                 C   s   t t| S r   )r   r   )r/   r   r   r   r      s    r   c                 C   s   t t| S r   )r   r   r%   r   r   r   r      s    r   c                    s:    du rt | S t d fddt| D S 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>       z randomString.<locals>.<listcomp>)getByteslenjoinrange)lengthr;   r   r:   r   r      s    r   c                 C   sB   t | t |krdS d}tt | D ]}|o:| | || k}q$|S )NFT)r@   rB   )s1s2resultir   r   r   const_eq   s    rH   )N) __doc____all__r   osrandomZopenid.oidutilr   r   hashlibobjectr   r	   r    r
   r'   r   r   ZSHA256_AVAILABLEZCrypto.Util.numberr(   r)   ImportErrorr,   r   r   urandomr?   r   r   r   r   rH   r   r   r   r   <module>   s8   

	

	