/usr/lib/python3/dist-packages/twisted/python/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/python/__pycache__/randbytes.cpython-310.pyc (3735B)
o
b
@ s| d Z ddlZddlZddlZeeddZejZG dd de Z
G dd de ZG dd d Ze Z
e
jZe
jZ[
g d
ZdS )zQ
Cryptographically secure random implementation, with fallback on normal random.
Ngetrandbitsc @ e Zd ZdZdS )SecureRandomNotAvailablezD
Exception raised when no secure random algorithm is found.
N__name__
__module____qualname____doc__ r
r
:/usr/lib/python3/dist-packages/twisted/python/randbytes.pyr r c @ r )SourceNotAvailablezQ
Internal exception used when a specific random source is not available.
Nr r
r
r
r r
r r
c @ sR e Zd ZdZdZeZdd ZdddZdd Ze j
Zed
d
Zdd Z
d
d 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
C s2 zt |W S ttfy } zt|d}~ww )zO
Wrapper around C{os.urandom} that cleanly manage its absence.
N)osurandomAttributeErrorNotImplementedErrorr
)selfnbyteser
r
r
_osUrandom- s zRandomFactory._osUrandomFc C sF z| |W S ty Y nw |rtjdtdd | |S td)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 available)r r
warningswarnRuntimeWarninginsecureRandomr )r r fallbackr
r
r secureRandom6 s
zRandomFactory.secureRandomc C s8 | j dur| |d }d|d | }t|S td)z3
Wrapper around C{os.getrandbits}.
N z%%0%dxr z#random.getrandbits is not available)r _fromhexr
)r r nhexBytesr
r
r _randBitsS s
zRandomFactory._randBits c s d fddt|D S )z6
Wrapper around the C{random} module.
r% c s g | ]}t t jgqS r
)bytesrandomchoice_BYTES).0ir r
r
d s z-RandomFactory._randModule..)joinrange)r r r
r, r _randModule` s zRandomFactory._randModulec C s4 dD ]}z
t | ||W S ty Y qw dS )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$ r0 N)getattrr
)r r srcr
r
r r f s
zRandomFactory.insecureRandomN)F)r r r r
randomSourcesr r r r$ r&