Commits

Andriy Kornatskyy  committed 55e4085

Fixed unpadding if string size is equal to block size.

  • Participants
  • Parent commits e9f06f2

Comments (0)

Files changed (1)

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

 
 
 def pad(s, block_size):
-    """ Pad with zeroes except make the last byte equal to the
+    """ Pad with zeros except make the last byte equal to the
         number of padding bytes.
 
         The convention with this method is usually always to
         add a padding string, even if the original plaintext was
-        already an exact multiple of 8 bytes.
+        already an exact multiple of `block_size` bytes.
 
         ``s`` - byte string.
 
         >>> s = unhexlify(b('666f720000000005'))
         >>> n(unpad(s, 8))
         'for'
-        >>> s = unhexlify(b('776f726b626f6f6b'))
+        >>> s = unhexlify(b('776f726b626f6f6b0000000000000008'))
         >>> n(unpad(s, 8))
         'workbook'
         >>> unpad('', 8)
     if n > 0:
         return None
     n = ord(s[-1])
-    if n >= block_size:
-        return s
+    if n > block_size:
+        return None
     return s[:-n]