summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_binascii.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-20 06:31:51 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-20 06:31:51 (GMT)
commite3037e114509913874a28746f5e05780919e909a (patch)
treedead0e6507d6c83d63d90750380b17c7fb566f5d /Lib/test/test_binascii.py
parentc74bb9d35060717eb8b658b89500ee18855c1080 (diff)
parent2ef7c478444f453a04ae63ecc3d3de07915ad2b0 (diff)
downloadcpython-e3037e114509913874a28746f5e05780919e909a.zip
cpython-e3037e114509913874a28746f5e05780919e909a.tar.gz
cpython-e3037e114509913874a28746f5e05780919e909a.tar.bz2
Issue #23728: binascii.crc_hqx() could return an integer outside of the range
0-0xffff for empty data.
Diffstat (limited to 'Lib/test/test_binascii.py')
-rw-r--r--Lib/test/test_binascii.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py
index 48fcb86..4e67887 100644
--- a/Lib/test/test_binascii.py
+++ b/Lib/test/test_binascii.py
@@ -135,6 +135,18 @@ class BinASCIITest(unittest.TestCase):
# Issue #7701 (crash on a pydebug build)
self.assertEqual(binascii.b2a_uu(b'x'), b'!> \n')
+ def test_crc_hqx(self):
+ crc = binascii.crc_hqx(self.type2test(b"Test the CRC-32 of"), 0)
+ crc = binascii.crc_hqx(self.type2test(b" this string."), crc)
+ self.assertEqual(crc, 14290)
+
+ self.assertRaises(TypeError, binascii.crc_hqx)
+ self.assertRaises(TypeError, binascii.crc_hqx, self.type2test(b''))
+
+ for crc in 0, 1, 0x1234, 0x12345, 0x12345678, -1:
+ self.assertEqual(binascii.crc_hqx(self.type2test(b''), crc),
+ crc & 0xffff)
+
def test_crc32(self):
crc = binascii.crc32(self.type2test(b"Test the CRC-32 of"))
crc = binascii.crc32(self.type2test(b" this string."), crc)