1. Andriy Kornatskyy
  2. wheezy.security

Commits

Andriy Kornatskyy  committed 188c3e1

Refactoring crypto/padding module tests.

  • Participants
  • Parent commits 6f72a24
  • Branches default

Comments (0)

Files changed (2)

File src/wheezy/security/crypto/padding.py

View file
         already an exact multiple of `block_size` bytes.
 
         ``s`` - byte string.
-
-        >>> from binascii import hexlify
-        >>> from wheezy.security.crypto.comp import b
-        >>> from wheezy.security.crypto.comp import n
-        >>> n(hexlify(pad(b('workbook'), 8)))
-        '776f726b626f6f6b0000000000000008'
-        >>> n(hexlify(pad(b('for'), 8)))
-        '666f720000000005'
-        >>> n(hexlify(pad(b(''), 8)))
-        '0000000000000008'
     """
     n = len(s) % block_size
     if n > 0:
     """ Strip right by the last byte number.
 
         ``s`` - byte string.
-
-        >>> from binascii import unhexlify
-        >>> from wheezy.security.crypto.comp import b
-        >>> from wheezy.security.crypto.comp import n
-        >>> s = unhexlify(b('666f720000000005'))
-        >>> n(unpad(s, 8))
-        'for'
-        >>> s = unhexlify(b('776f726b626f6f6b0000000000000008'))
-        >>> n(unpad(s, 8))
-        'workbook'
-        >>> unpad('', 8)
-        >>> unpad('abcd', 8)
     """
     n = len(s)
     if n == 0:

File src/wheezy/security/crypto/tests/test_padding.py

View file
+
+""" Unit tests for ``wheezy.security.crypto.padding``.
+"""
+
+import unittest
+
+
+class PaddingTestCase(unittest.TestCase):
+
+    def test_pad(self):
+        """ Test pad.
+        """
+        from binascii import hexlify
+        from wheezy.security.crypto.comp import b
+        from wheezy.security.crypto.comp import n
+        from wheezy.security.crypto.padding import pad
+
+        s = n(hexlify(pad(b('workbook'), 8)))
+        assert '776f726b626f6f6b0000000000000008' == s
+        s = n(hexlify(pad(b('for'), 8)))
+        assert '666f720000000005' == s
+        s = n(hexlify(pad(b(''), 8)))
+        assert '0000000000000008' == s
+
+    def test_unpad(self):
+        """ Test unpad.
+        """
+        from binascii import unhexlify
+        from wheezy.security.crypto.comp import b
+        from wheezy.security.crypto.comp import n
+        from wheezy.security.crypto.padding import unpad
+
+        s = unhexlify(b('666f720000000005'))
+        s = n(unpad(s, 8))
+        assert 'for' == s
+        s = unhexlify(b('776f726b626f6f6b0000000000000008'))
+        s = n(unpad(s, 8))
+        assert 'workbook' == s
+        assert None == unpad('', 8)
+        # incorrect padding
+        assert None == unpad('abc', 8)
+        assert None == unpad('abcd', 8)