def test_zero_padding(self): padding = ZeroPadding(block_size=16) # Full length source = b'loremipsumdolors' encoded_source = padding.encode(source) self.assertEqual(encoded_source, source) self.assertEqual(len(encoded_source), 16) self.assertEqual(padding.decode(encoded_source), source) # Length 2 source = b'hi' encoded_source = padding.encode(source) self.assertEqual(encoded_source, source + b'\x00' * 14) self.assertEqual(len(encoded_source), 16) self.assertEqual(padding.decode(encoded_source), source) # Length 1 source = b'h' encoded_source = padding.encode(source) self.assertEqual(encoded_source, source + b'\x00' * 15) self.assertEqual(len(encoded_source), 16) self.assertEqual(padding.decode(encoded_source), source) # Zero length self.assertEqual(padding.decode(b''), b'') # Wrong value to decode with self.assertRaises(AssertionError): padding.decode(b'no-padding')
def test_zero_padding(self) -> None: padding = ZeroPadding(block_size=16) # Full length source = b"loremipsumdolors" encoded_source = padding.encode(source) self.assertEqual(encoded_source, source) self.assertEqual(len(encoded_source), 16) self.assertEqual(padding.decode(encoded_source), source) # Length 2 source = b"hi" encoded_source = padding.encode(source) self.assertEqual(encoded_source, source + b"\x00" * 14) self.assertEqual(len(encoded_source), 16) self.assertEqual(padding.decode(encoded_source), source) # Length 1 source = b"h" encoded_source = padding.encode(source) self.assertEqual(encoded_source, source + b"\x00" * 15) self.assertEqual(len(encoded_source), 16) self.assertEqual(padding.decode(encoded_source), source) # Zero length self.assertEqual(padding.decode(b""), b"") # Wrong value to decode with self.assertRaises(AssertionError): padding.decode(b"no-padding")