Debian Codegraph @

lib/Crypto/SelfTest/Util/test_Counter.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # SelfTest/Util/test_Counter: Self-test for the Crypto.Util.Counter module
4 #
5 # Written in 2009 by Dwayne C. Litzenberger <[email protected]>
6 #
7 # ===================================================================
8 # The contents of this file are dedicated to the public domain. To
9 # the extent that dedication to the public domain is not available,
10 # everyone is granted a worldwide, perpetual, royalty-free,
11 # non-exclusive license to exercise all rights associated with the
12 # contents of this file for any purpose whatsoever.
13 # No rights are reserved.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 # SOFTWARE.
23 # ===================================================================
24
25 """Self-tests for Crypto.Util.Counter"""
26
27 from Crypto.Util.py3compat import *
28
29 import unittest
30
31 class CounterTests(unittest.TestCase):
32 def setUp(self):
33 global Counter
34 from Crypto.Util import Counter
35
36 def test_BE(self):
37 """Big endian"""
38 c = Counter.new(128)
39 c = Counter.new(128, little_endian=False)
40
41 def test_LE(self):
42 """Little endian"""
43 c = Counter.new(128, little_endian=True)
44
45 def test_nbits(self):
46 c = Counter.new(nbits=128)
47 self.assertRaises(ValueError, Counter.new, 129)
48
49 def test_prefix(self):
50 c = Counter.new(128, prefix=b("xx"))
51
52 def test_suffix(self):
53 c = Counter.new(128, suffix=b("xx"))
54
55 def test_iv(self):
56 c = Counter.new(128, initial_value=2)
57 self.assertRaises(ValueError, Counter.new, 16, initial_value=0x1FFFF)
58
59 def get_tests(config={}):
60 from Crypto.SelfTest.st_common import list_test_cases
61 return list_test_cases(CounterTests)
62
63 if __name__ == '__main__':
64 suite = lambda: unittest.TestSuite(get_tests())
65 unittest.main(defaultTest='suite')
66
67 # vim:set ts=4 sw=4 sts=4 expandtab: