
    )Jf                     :   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e	          Z
 e
ej                  Z e
ej                  Zd Zd Zd	 Zd
 ZdZ	 ddlmZmZ d Zd Zn# e$ r ddlZd Zd ZY nw xY wej        Zej        Zd Zd ZddZ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                       e Zd Zd ZdS )HashContainerc                 <    || _          |            j        | _        d S N)newdigest_size)selfhash_constructors     S/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/cryptutil.py__init__zHashContainer.__init__'   s#    #++--9    N)__name__
__module____qualname__r    r   r   r   r   &   s#        : : : : :r   r   c                     t          | t                    rt          | d          } t          |t                    rt          |d          }t          j        | |t
                                                    S Nutf-8)encoding)
isinstancestrbyteshmacr   sha1_moduledigestkeytexts     r   r   r   0   sj    #s +C'***$ -TG,,,8C{++22444r   c                     t          | t                    rt          | d          } t                              |                                           S r   )r"   r#   r$   r&   r   r'   ss    r   r
   r
   8   sD    !S '!g&&&??1$$&&&r   c                     t          | t                    rt          | d          } t          |t                    rt          |d          }t          j        | |t
                                                    S r   )r"   r#   r$   r%   r   sha256_moduler'   r(   s     r   r   r   >   sj    #s +C'***$ -TG,,,8C}--44666r   c                     t          | t                    rt          | d          } t                              |                                           S r   )r"   r#   r$   r/   r   r'   r,   s    r   r   r   F   sF    !S '!g&&&Q&&(((r   T)long_to_bytesbytes_to_longc                 p    | dk     rt          d          t          |           }|d         dk    rd|z   S |S )Nr   -This function only supports positive integers       )
ValueErrorr1   )l
bytestrings     r   r   r   f   sG    q55LMMM"1%%
a=3Z''r   c                 x    | st          d          | d         dk    rt          d          t          |           S )Nz Empty string passed to strToLongr   r5   r4   )r7   r2   )r9   s    r   r   r   p   sF     	A?@@@a=3LMMMZ(((r   c                     | dk    rdS t          t          j        |                     }|                                 t	          |          S )Nr   r6   )	bytearraypickleencode_longreverser$   )r8   bs     r   r   r   V   s@    667f(++,,			Qxxr   c                     t          | t                    r|                     d          } t          |           }|                                 t          j        t          |                    S )Nr    )r"   r#   encoder<   r?   r=   decode_longr$   )r-   r@   s     r   r   r   ]   sT    a 	"!!AaLL			!%((+++r   c                 :    t          t          |                     S r   )r   r   )r8   s    r   r   r      s    LOO$$$r   c                 :    t          t          |                     S r   )r   r   r,   s    r   r   r      s    
1&&&r   c                     t          |           S t                    d                    fdt          |           D                       S )z:Produce a string of length random bytes, chosen from chrs.N c                 :    g | ]}t                             S r   )r	   ).0_chrsns     r   
<listcomp>z randomString.<locals>.<listcomp>   s$    BBBqYq\\*BBBr   )getByteslenjoinrange)lengthrK   rL   s    `@r   r   r      sR    |IIwwBBBBBE&MMBBBCCCr   c                     t          |           t          |          k    rdS d}t          t          |                     D ]}|o| |         ||         k    }|S )NFT)rO   rQ   )s1s2resultis       r   const_eqrX      s[    
2ww#b''uF3r77^^ - -,RUbe^Mr   r   ) __doc____all__r%   osrandomopenid.oidutilr   r   hashlibobjectr   r
   r&   r   r/   r   r   SHA256_AVAILABLECrypto.Util.numberr1   r2   r   r   ImportErrorr=   urandomrN   r	   r   r   r   rX   r   r   r   <module>rd      s       				  / / / / / / / / : : : : :F : : : mGL))gn--5 5 5' ' '7 7 7) ) )  ))????????.  ) ) ) )A  , , , MMM  , , , , ,,V : 	% % %' ' 'D D D D    s   A+ +A=<A=