Ë
    oj´  ã                   óÔ   — d Z ddlZddlZddlZ eedd«      Zej                  Z G d„ de	«      Z
 G d„ de	«      Z G d„ d	«      Z e«       Zej                  Zej                  Z[g d
¢Zy)zQ
Cryptographically secure random implementation, with fallback on normal random.
é    NÚgetrandbitsc                   ó   — e Zd ZdZy)ÚSecureRandomNotAvailablezD
    Exception raised when no secure random algorithm is found.
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    ú:/usr/lib/python3/dist-packages/twisted/python/randbytes.pyr   r      ó   „ òr   r   c                   ó   — e Zd ZdZy)ÚSourceNotAvailablezQ
    Internal exception used when a specific random source is not available.
    Nr   r   r   r   r   r      r   r   r   c                   ó˜   — e Zd ZdZdZeZdedefd„Zddede	defd„Z
dedefd„Zej                  Z ed	d	«      Zdedefd
„Zdedefd„Zy)Ú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   ÚnbytesÚreturnc                 ór   — 	 t        j                  |«      S # t        t        f$ r}t	        |«      ‚d}~ww xY w)zO
        Wrapper around C{os.urandom} that cleanly manage its absence.
        N)ÚosÚurandomÚAttributeErrorÚNotImplementedErrorr   )Úselfr   Úes      r   Ú
_osUrandomzRandomFactory._osUrandom-   s7   € ð	(Ü—:‘:˜fÓ%Ð%øÜÔ 3Ð4ò 	(Ü$ QÓ'Ð'ûð	(ús   ‚ —6¦1±6Úfallbackc                 ó¸   — 	 | j                  |«      S # t        $ r Y nw xY w|r-t        j                  dt        d¬«       | j                  |«      S t        d«      ‚)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   ÚwarningsÚwarnÚRuntimeWarningÚinsecureRandomr   )r   r   r   s      r   ÚsecureRandomzRandomFactory.secureRandom6   sd   € ð	Ø—?‘? 6Ó*Ð*øÜ!ò 	Ùð	úñ Ü�M‰MðMä'Øõ	ð ×&Ñ& vÓ.Ð.ä*Ð+NÓOÐOó   ‚ “	žc                 ó„   — | j                   �*| j                  |dz  «      }d|dz  z  |z  }t        |«      S t        d«      ‚)z3
        Wrapper around C{os.getrandbits}.
        é   z%%0%dxr   z#random.getrandbits is not available)r   Ú_fromhexr   )r   r   ÚnÚhexBytess       r   Ú	_randBitszRandomFactory._randBitsS   sN   € ð ×ÑÐ'Ø× Ñ  ¨!¡Ó,ˆAØ  F¨Q¡JÑ/°1Ñ4ˆHÜ˜HÓ%Ð%Ü Ð!FÓGÐGr   r   c           
      óª   — dj                  t        |«      D �cg c]+  }t        t        j                  | j
                  «      g«      ‘Œ- c}«      S c c}w )z6
        Wrapper around the C{random} module.
        r   )ÚjoinÚrangeÚbytesÚrandomÚchoiceÚ_BYTES)r   r   Úis      r   Ú_randModulezRandomFactory._randModule`   s:   € ð �x‰xÄeÈFÃmÖTÀœ¤§¡¨d¯k©kÓ :Ð;Õ<ÒTÓUÐUùÒTs   ™0Ac                 óf   — 	 | j                  |«      S # t        $ r Y nw xY w| j                  |«      S )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-   r   r6   )r   r   s     r   r%   zRandomFactory.insecureRandomf   s9   € ð	Ø—>‘> &Ó)Ð)øÜ!ò 	Ùð	úà×Ñ Ó'Ð'r'   N)F)r   r   r	   r
   ÚrandomSourcesr   Úintr1   r   Úboolr&   r-   Ú	maketransÚ
_maketransr4   r6   r%   r   r   r   r   r      sš   „ ñð €Mà€Kð( ð (¨ó (ñP 3ð P°$ð PÀ5ó Pð:H ð H¨ó Hð —‘€JÙ˜˜SÓ!€FðV #ð V¨%ó Vð( Sð (¨Uô (r   r   )r&   r%   r   )r
   r   r2   r"   Úgetattrr   r1   Úfromhexr*   ÚRuntimeErrorr   r   r   Úfactoryr&   r%   Ú__all__r   r   r   ú<module>rB      s{   ðñ
ó
 
Û Û á�f˜m¨TÓ2€à�=‰=€ô˜|ô ô˜ô ÷U(ñ U(ñp ‹/€à×#Ñ#€à×'Ñ'€àò I�r   