<s> """<STR_LIT>""" <EOL> __revision__ = "<STR_LIT>" <EOL> import sys <EOL> if sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> and sys . version_info [ <NUM_LIT:1> ] == <NUM_LIT:1> : <EOL> from Crypto . Util . py21compat import * <EOL> from Crypto . Util . py3compat import * <EOL> import unittest <EOL> from binascii import b2a_hex <EOL> class FortunaAccumulatorTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> global FortunaAccumulator <EOL> from Crypto . Random . Fortuna import FortunaAccumulator <EOL> def test_FortunaPool ( self ) : <EOL> """<STR_LIT>""" <EOL> pool = FortunaAccumulator . FortunaPool ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , pool . length ) <EOL> self . assertEqual ( "<STR_LIT>" , pool . hexdigest ( ) ) <EOL> pool . append ( b ( '<STR_LIT:abc>' ) ) <EOL> self . assertEqual ( <NUM_LIT:3> , pool . length ) <EOL> self . assertEqual ( "<STR_LIT>" , pool . hexdigest ( ) ) <EOL> pool . append ( b ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( <NUM_LIT> , pool . length ) <EOL> self . assertEqual ( b ( '<STR_LIT>' ) , b2a_hex ( pool . digest ( ) ) ) <EOL> pool . reset ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , pool . length ) <EOL> pool . append ( b ( '<STR_LIT:a>' ) * <NUM_LIT:10> ** <NUM_LIT:6> ) <EOL> self . assertEqual ( <NUM_LIT:10> ** <NUM_LIT:6> , pool . length ) <EOL> self . assertEqual ( b ( '<STR_LIT>' ) , b2a_hex ( pool . digest ( ) ) ) <EOL> def test_which_pools ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( AssertionError , FortunaAccumulator . which_pools , <NUM_LIT:0> ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:1> ) , [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> ) , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:3> ) , [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:4> ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:5> ) , [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:6> ) , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:7> ) , [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:8> ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:32> ) : <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> L ** i - <NUM_LIT:1> ) , [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> L ** i ) , range ( i + <NUM_LIT:1> ) ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> L ** i + <NUM_LIT:1> ) , [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> L ** <NUM_LIT> ) , range ( <NUM_LIT:32> ) ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> L ** <NUM_LIT:32> ) , range ( <NUM_LIT:32> ) ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> L ** <NUM_LIT> ) , range ( <NUM_LIT:32> ) ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> L ** <NUM_LIT> ) , range ( <NUM_LIT:32> ) ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> L ** <NUM_LIT> ) , range ( <NUM_LIT:32> ) ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> L ** <NUM_LIT> ) , range ( <NUM_LIT:32> ) ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> L ** <NUM_LIT:64> ) , range ( <NUM_LIT:32> ) ) <EOL> self . assertEqual ( FortunaAccumulator . which_pools ( <NUM_LIT:2> L ** <NUM_LIT> ) , range ( <NUM_LIT:32> ) ) <EOL> def test_accumulator ( self ) : <EOL> """<STR_LIT>""" <EOL> fa = FortunaAccumulator . FortunaAccumulator ( ) <EOL> self . assertRaises ( AssertionError , fa . random_data , <NUM_LIT:1> ) <EOL> for p in range ( <NUM_LIT:32> ) : <EOL> fa . add_random_event ( <NUM_LIT> , p , b ( "<STR_LIT:X>" ) * <NUM_LIT:32> ) <EOL> self . assertEqual ( <NUM_LIT:32> + <NUM_LIT:2> , fa . pools [ p ] . length ) <EOL> self . assertRaises ( AssertionError , fa . random_data , <NUM_LIT:1> ) <EOL> for p in range ( <NUM_LIT:32> ) : <EOL> fa . add_random_event ( <NUM_LIT> , p , b ( "<STR_LIT:X>" ) * <NUM_LIT:32> ) <EOL> self . assertEqual ( ( <NUM_LIT:32> + <NUM_LIT:2> ) * <NUM_LIT:2> , fa . pools [ p ] . length ) <EOL> self . assertEqual ( "<STR_LIT>" , <EOL> fa . pools [ <NUM_LIT:0> ] . hexdigest ( ) ) <EOL> self . assertEqual ( None , fa . generator . key ) <EOL> self . assertEqual ( <NUM_LIT:0> , fa . generator . counter . next_value ( ) ) <EOL> result = fa . random_data ( <NUM_LIT:32> ) <EOL> self . assertEqual ( b ( "<STR_LIT>" "<STR_LIT>" ) , b2a_hex ( result ) ) <EOL> self . assertEqual ( b ( "<STR_LIT>" ) , b2a_hex ( fa . generator . key ) ) <EOL> self . assertEqual ( <NUM_LIT:5> , fa . generator . counter . next_value ( ) ) <EOL> def test_accumulator_pool_length ( self ) : <EOL> """<STR_LIT>""" <EOL> fa = FortunaAccumulator . FortunaAccumulator ( ) <EOL> self . assertEqual ( fa . min_pool_size , <NUM_LIT:64> ) <EOL> self . assertRaises ( AssertionError , fa . random_data , <NUM_LIT:1> ) <EOL> for i in range ( <NUM_LIT:15> ) : <EOL> for p in range ( <NUM_LIT:32> ) : <EOL> fa . add_random_event ( <NUM_LIT:2> , p , b ( "<STR_LIT>" ) ) <EOL> self . assertRaises ( AssertionError , fa . random_data , <NUM_LIT:1> ) <EOL> fa . add_random_event ( <NUM_LIT:2> , <NUM_LIT:0> , b ( "<STR_LIT>" ) ) <EOL> fa . random_data ( <NUM_LIT:1> ) <EOL> def get_tests ( config = { } ) : <EOL> from Crypto . SelfTest . st_common import list_test_cases <EOL> return list_test_cases ( FortunaAccumulatorTests ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> suite = lambda : unittest . TestSuite ( get_tests ( ) ) <EOL> unittest . main ( defaultTest = '<STR_LIT>' ) </s>
