]> Cypherpunks.ru repositories - pygost.git/blobdiff - pygost/test_gost3413.py
(un)pad_iso10126
[pygost.git] / pygost / test_gost3413.py
index f670d7e85ebac121696c39651b6ca71d4a8bb567..159f7fe9c02dc0e8d8ecaa4c5491bdba7e535684 100644 (file)
@@ -1,6 +1,6 @@
 # coding: utf-8
 # PyGOST -- Pure Python GOST cryptographic functions library
-# Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
+# Copyright (C) 2015-2022 Sergey Matveev <stargrave@stargrave.org>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -36,7 +36,9 @@ from pygost.gost3413 import mac
 from pygost.gost3413 import mac_acpkm_master
 from pygost.gost3413 import ofb
 from pygost.gost3413 import pad2
+from pygost.gost3413 import pad_iso10126
 from pygost.gost3413 import unpad2
+from pygost.gost3413 import unpad_iso10126
 from pygost.utils import hexdec
 from pygost.utils import hexenc
 from pygost.utils import strxor
@@ -747,3 +749,18 @@ A8 1C 79 A0 4F 29 66 0E A3 FD A8 74 C6 30 79 9E
             ),
             hexdec("FBB8DCEE45BEA67C35F58C5700898E5D"),
         )
+
+
+class ISO10126Test(TestCase):
+    def test_symmetric(self):
+        for _ in range(100):
+            for blocksize in (GOST3412Magma.blocksize, GOST3412Kuznechik.blocksize):
+                data = urandom(randint(0, blocksize * 3))
+                padded = pad_iso10126(data, blocksize)
+                self.assertSequenceEqual(unpad_iso10126(padded, blocksize), data)
+                with self.assertRaises(ValueError):
+                    unpad_iso10126(padded[1:], blocksize)
+
+    def test_small(self):
+        with self.assertRaises(ValueError):
+            unpad_iso10126(b"foobar\x00\x09", 8)