HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/python/__pycache__/randbytes.cpython-38.pyc
U


W[w�@s�dZddlmZmZddlZddlZddlZddlZddlm	Z	e
edd�Ze	rXej
Zndd�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�Ze�ZejZejZ[ddd	gZdS)zQ
Cryptographically secure random implementation, with fallback on normal random.
�)�division�absolute_importN)�_PY3�getrandbitscCs
|�d�S)N�hex)�decode)�hexBytes�r	�:/usr/lib/python3/dist-packages/twisted/python/randbytes.py�_fromhexsrc@seZdZdZdS)�SecureRandomNotAvailablezD
    Exception raised when no secure random algorithm is found.
    N��__name__�
__module__�__qualname__�__doc__r	r	r	r
rsrc@seZdZdZdS)�SourceNotAvailablezQ
    Internal exception used when a specific random source is not available.
    Nr
r	r	r	r
rsrc@sfeZdZdZdZeZdd�Zddd�Zdd	�Ze	rBe
jZd
d�Z
nejZdd�Z
ed
d
�Zdd�ZdS)�
RandomFactoryz�
    Factory providing L{secureRandom} and L{insecureRandom} methods.

    You shouldn't have to instantiate this class, use the module level
    functions instead: it is an implementation detail and could be removed or
    changed arbitrarily.
    r	c
Cs@zt�|�WSttfk
r:}zt|��W5d}~XYnXdS)zO
        Wrapper around C{os.urandom} that cleanly manage its absence.
        N)�os�urandom�AttributeError�NotImplementedErrorr)�self�nbytes�er	r	r
�
_osUrandom5szRandomFactory._osUrandomFcCsLz|�|�WStk
r YnX|r@tjdtdd�|�|�Std��dS)ak
        Return a number of secure random bytes.

        @param nbytes: number of bytes to generate.
        @type nbytes: C{int}
        @param fallback: Whether the function should fallback on non-secure
            random or not.  Default to C{False}.
        @type fallback: C{bool}

        @return: a string of random bytes.
        @rtype: C{str}
        zPurandom unavailable - proceeding with non-cryptographically secure random source�)�category�
stacklevelz!No secure random source availableN)rr�warnings�warn�RuntimeWarning�insecureRandomr)rrZfallbackr	r	r
�secureRandom?s
�
zRandomFactory.secureRandomcCs<|jdk	r0|�|d�}d|d|}t|�Std��dS)z3
        Wrapper around C{os.getrandbits}.
        N�z%%0%dxrz#random.getrandbits is not available)rrr)rr�nrr	r	r
�	_randBits\s

zRandomFactory._randBitscsd��fdd�t|�D��S)�>
            Wrapper around the C{random} module.
            �csg|]}tt��j�g��qSr	)�bytes�random�choice�_BYTES��.0�i�rr	r
�
<listcomp>ms�-RandomFactory._randModule.<locals>.<listcomp>��join�range�rrr	r0r
�_randModuleis�zRandomFactory._randModulecsd��fdd�t|�D��S)r'r(csg|]}t��j��qSr	)r*r+r,r-r0r	r
r1usr2r3r6r	r0r
r7qs�r(c	Cs8dD].}zt||�|�WStk
r0YqXqdS)z�
        Return a number of non secure random bytes.

        @param nbytes: number of bytes to generate.
        @type nbytes: C{int}

        @return: a string of random bytes.
        @rtype: C{str}
        )r&r7N)�getattrr)rr�srcr	r	r
r"{s

zRandomFactory.insecureRandomN)F)rrrrZ
randomSourcesrrr#r&rr)�	maketransZ
_maketransr7�stringr,r"r	r	r	r
r&s	



rr#r")rZ
__future__rrrrr*r;Ztwisted.python.compatrr8rr)�fromhexr�RuntimeErrorrr�objectr�factoryr#r"�__all__r	r	r	r
�<module>s g