§
    Y¦·f‘  ã                  óø   — d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ  G d„ de¦  «        Z G d	„ d
¦  «        Z G d„ deej        ¦  «        Z G d„ deej        ¦  «        Z G d„ deej        ¦  «        ZdS )z-
Test cases for L{twisted.python.randbytes}.
é    )Úannotations)ÚCallable)ÚNoReturnÚProtocol)Ú	randbytes)Úunittestc                  ó   — e Zd Zdd„Zdd„ZdS )	Ú_SupportsAssertionsÚaÚobjectÚbÚreturnc                ó   — d S ©N© ©Úselfr   r   s      úM/var/www/html/env/lib/python3.11/site-packages/twisted/test/test_randbytes.pyÚassertEqualz_SupportsAssertions.assertEqual   ó   € Øˆó    c                ó   — d S r   r   r   s      r   ÚassertNotEqualz"_SupportsAssertions.assertNotEqual   r   r   N)r   r   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r
   r
      s<   € € € € € ðð ð ð ðð ð ð ð ð r   r
   c                  ó   — e Zd ZdZd
d„Zd	S )ÚSecureRandomTestCaseBasez1
    Base class for secureRandom test cases.
    r   r
   ÚsourceúCallable[[int], bytes]r   ÚNonec                ó  — t          dd¦  «        D ]t} ||¦  «        }|                      t          |¦  «        |¦  «          ||¦  «        }|                      t          |¦  «        |¦  «         |                      ||¦  «         ŒudS )a|  
        The given random bytes source should return the number of bytes
        requested each time it is called and should probably not return the
        same bytes on two consecutive calls (although this is a perfectly
        legitimate occurrence and rejecting it may generate a spurious failure
        -- maybe we'll get lucky and the heat death with come first).
        é   é   N)Úranger   Úlenr   )r   r   ÚnbytesÚsÚs2s        r   Ú_checkzSecureRandomTestCaseBase._check   s   € õ ˜B ‘m”mð 	'ð 	'ˆFØv‘”ˆAØ×ÒS ™VœV VÑ,Ô,Ð,Ø˜‘”ˆBØ×ÒS ™WœW fÑ-Ô-Ð-à×Ò  AÑ&Ô&Ð&Ð&ð	'ð 	'r   N)r   r
   r   r    r   r!   )r   r   r   Ú__doc__r*   r   r   r   r   r      s2   € € € € € ðð ð'ð 'ð 'ð 'ð 'ð 'r   r   c                  ó   — e Zd ZdZdd„ZdS )ÚSecureRandomTestsz4
    Test secureRandom under normal conditions.
    r   r!   c                óD   — |                       t          j        ¦  «         dS )z£
        L{randbytes.secureRandom} should return a string of the requested
        length and make some effort to make its result otherwise unpredictable.
        N)r*   r   ÚsecureRandom©r   s    r   Útest_normalzSecureRandomTests.test_normal4   s   € ð
 	Š•IÔ*Ñ+Ô+Ð+Ð+Ð+r   N©r   r!   )r   r   r   r+   r1   r   r   r   r-   r-   /   s2   € € € € € ðð ð,ð ,ð ,ð ,ð ,ð ,r   r-   c                  ó2   — e Zd ZdZdd„Zdd„Zdd	„Zdd
„ZdS )ÚConditionalSecureRandomTestsz<
    Test random sources one by one, then remove it to.
    r   r!   c                ó6   — t          j        ¦   «         | _        dS )zJ
        Create a L{randbytes.RandomFactory} to use in the tests.
        N)r   ÚRandomFactoryÚfactoryr0   s    r   ÚsetUpz"ConditionalSecureRandomTests.setUpC   s   € õ !Ô.Ñ0Ô0ˆŒˆˆr   r'   r   r   c                ó(   — t          j        ¦   «         ‚)zL
        A factory raising an error when a source is not available.
        )r   ÚSourceNotAvailable)r   r'   s     r   ÚerrorFactoryz)ConditionalSecureRandomTests.errorFactoryI   s   € õ Ô*Ñ,Ô,Ð,r   c                óD   — |                       | j        j        ¦  «         dS )zy
        L{RandomFactory._osUrandom} should work as a random source whenever
        L{os.urandom} is available.
        N)r*   r7   Ú
_osUrandomr0   s    r   Útest_osUrandomz+ConditionalSecureRandomTests.test_osUrandomO   s!   € ð
 	ŠD”LÔ+Ñ,Ô,Ð,Ð,Ð,r   c                ó  ‡ — ‰ j         ‰ j        _        ‰                      t          j        ‰ j        j        d¦  «         dˆ fd„}‰                      t          dt          |¦  «        }‰  
                    t          |¦  «        d¦  «         dS )zt
        Remove all secure sources and assert it raises a failure. Then try the
        fallback parameter.
        é   r   Úbytesc                 ó<   •— ‰ j                              dd¬¦  «        S )Nr@   T)Úfallback)r7   r/   r0   s   €r   ÚwrapperzBConditionalSecureRandomTests.test_withoutAnything.<locals>.wrapper`   s   ø€ Ø”<×,Ò,¨R¸$Ð,Ñ?Ô?Ð?r   zPurandom unavailable - proceeding with non-cryptographically secure random sourceN)r   rA   )r;   r7   r=   ÚassertRaisesr   ÚSecureRandomNotAvailabler/   ÚassertWarnsÚRuntimeWarningÚ__file__r   r&   )r   rD   r(   s   `  r   Útest_withoutAnythingz1ConditionalSecureRandomTests.test_withoutAnythingV   s§   ø€ ð
 #'Ô"3ˆŒÔØ×ÒÝÔ.°´Ô0IÈ2ñ	
ô 	
ð 	
ð	@ð 	@ð 	@ð 	@ð 	@ð 	@ð ×ÒÝðIåØñ
ô 
ˆð 	×Ò˜Q™œ Ñ$Ô$Ð$Ð$Ð$r   Nr2   )r'   r   r   r   )r   r   r   r+   r8   r;   r>   rJ   r   r   r   r4   r4   <   sn   € € € € € ðð ð1ð 1ð 1ð 1ð-ð -ð -ð -ð-ð -ð -ð -ð%ð %ð %ð %ð %ð %r   r4   c                  ó"   — e Zd ZdZdd„Zdd„ZdS )ÚRandomBaseTestsz%
    'Normal' random test cases.
    r   r!   c                óD   — |                       t          j        ¦  «         dS )z"
        Test basic case.
        N)r*   r   ÚinsecureRandomr0   s    r   r1   zRandomBaseTests.test_normalr   s   € ð 	Š•IÔ,Ñ-Ô-Ð-Ð-Ð-r   c                ón   — t          j        ¦   «         }d|_        |                      |j        ¦  «         dS )zG
        Test C{insecureRandom} without C{random.getrandbits}.
        N)r   r6   Úgetrandbitsr*   rN   )r   r7   s     r   Útest_withoutGetrandbitsz'RandomBaseTests.test_withoutGetrandbitsx   s5   € õ Ô)Ñ+Ô+ˆØ"ˆÔØŠGÔ*Ñ+Ô+Ð+Ð+Ð+r   Nr2   )r   r   r   r+   r1   rQ   r   r   r   rL   rL   m   sF   € € € € € ðð ð.ð .ð .ð .ð,ð ,ð ,ð ,ð ,ð ,r   rL   N)r+   Ú
__future__r   Útypingr   Útyping_extensionsr   r   Útwisted.pythonr   Útwisted.trialr   r
   r   ÚTestCaser-   ÚSynchronousTestCaser4   rL   r   r   r   ú<module>rY      s^  ððð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0à $Ð $Ð $Ð $Ð $Ð $Ø "Ð "Ð "Ð "Ð "Ð "ðð ð ð ð ˜(ñ ô ð ð'ð 'ð 'ð 'ð 'ñ 'ô 'ð 'ð,
,ð 
,ð 
,ð 
,ð 
,Ð0°(Ô2Cñ 
,ô 
,ð 
,ð.%ð .%ð .%ð .%ð .%Ø˜hÔ:ñ.%ô .%ð .%ðb,ð ,ð ,ð ,ð ,Ð.°Ô0Lñ ,ô ,ð ,ð ,ð ,r   