
    f                     L   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ej2                  Zej6                  Zd Zd ZddZd Zy# e$ r ddlZd Zd ZY 7w xY w)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y)HashContainerc                 >    || _          |       j                  | _        y N)newdigest_size)selfhash_constructors     K/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/openid/cryptutil.py__init__zHashContainer.__init__'   s    #+-9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
              j                         S Nutf-8)encoding)
isinstancestrbyteshmacr   sha1_moduledigestkeytexts     r   r   r   0   sJ    #sC'*$TG,88C{+2244r   c                     t        | t              rt        | d      } t        j	                  |       j                         S r   )r"   r#   r$   r&   r   r'   ss    r   r
   r
   8   s0    !S!g&??1$$&&r   c                     t        | t              rt        | d      } t        |t              rt        |d      }t        j                  | |t
              j                         S r   )r"   r#   r$   r%   r   sha256_moduler'   r(   s     r   r   r   >   sJ    #sC'*$TG,88C}-4466r   c                     t        | t              rt        | d      } t        j	                  |       j                         S r   )r"   r#   r$   r/   r   r'   r,   s    r   r   r   F   s2    !S!g&Q&&((r   T)long_to_bytesbytes_to_longc                 V    | dk  rt        d      t        |       }|d   dkD  rd|z   S |S )Nr   -This function only supports positive integers       )
ValueErrorr1   )l
bytestrings     r   r   r   f   s<    q5LMM"1%
a=3Z''r   c                 X    | st        d      | d   dkD  rt        d      t        |       S )Nz Empty string passed to strToLongr   r5   r4   )r7   r2   )r9   s    r   r   r   p   s4    ?@@a=3LMMZ((r   c                     | dk(  ryt        t        j                  |             }|j                          t	        |      S )Nr   r6   )	bytearraypickleencode_longreverser$   )r8   bs     r   r   r   V   s3    6f((+,			Qxr   c                     t        | t              r| j                  d      } t        |       }|j	                          t        j                  t        |            S )Nr    )r"   r#   encoder<   r?   r=   decode_longr$   )r-   r@   s     r   r   r   ]   sA    a!AaL			!!%(++r   c                 *    t        t        |             S r   )r   r   )r8   s    r   r   r      s    LO$$r   c                 *    t        t        |             S r   )r   r   r,   s    r   r   r      s    
1&&r   c           	          |t        |       S t        |      }dj                  t        |       D cg c]  }|t	        |          c}      S c c}w )z:Produce a string of length random bytes, chosen from chrs. )getByteslenjoinranger	   )lengthchrsn_s       r   r   r      sE    |IwwE&MBqYq\*BCCBs   Ac                     t        |       t        |      k7  ryd}t        t        |             D ]  }|xr | |   ||   k(  } |S )NFT)rI   rK   )s1s2resultis       r   const_eqrU      sN    
2w#b'F3r7^ -,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=   urandomrH   r	   r   r   r   rU   r   r   r   <module>ra      s     	  / :F : GLL)gnn-5'7)  ))?.) :: 	%'DE  , ,,s   B B#"B#