File: test_dhcrypto.py

package info (click to toggle)
python-secretstorage 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 200 kB
  • ctags: 167
  • sloc: python: 695; makefile: 17; sh: 8
file content (29 lines) | stat: -rw-r--r-- 908 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Tests for SecretStorage
# Author: Dmitry Shachnev, 2014
# License: BSD

# This file tests the dhcrypto module.

import unittest
from secretstorage.dhcrypto import long_to_bytes, bytes_to_long

class ConversionTest(unittest.TestCase):
	"""A test case that tests conversion functions
	between bytes and long."""

	def test_long_to_bytes(self):
		self.assertEqual(long_to_bytes(1), b'\x01')
		self.assertEqual(long_to_bytes(258), b'\x01\x02')
		self.assertEqual(long_to_bytes(1 << 64), b'\x01' + b'\x00' * 8)

	def test_bytes_to_long(self):
		self.assertEqual(bytes_to_long(b'\x01'), 1)
		self.assertEqual(bytes_to_long(b'\x01\x02'), 258)
		self.assertEqual(bytes_to_long(b'\x01' + b'\x00' * 8), 1 << 64)

	def test_array_to_long(self):
		self.assertEqual(bytes_to_long([1] + [0] * 8), 1 << 64)
		self.assertEqual(bytes_to_long(bytearray([1] + [0] * 8)), 1 << 64)

if __name__ == '__main__':
	unittest.main()