diff --git a/bitsharesbase/memo.py b/bitsharesbase/memo.py index 597486ee..3d69655f 100644 --- a/bitsharesbase/memo.py +++ b/bitsharesbase/memo.py @@ -63,8 +63,8 @@ def _pad(s, BS): def _unpad(s, BS): - count = int(struct.unpack('B', bytes(s[-1], 'ascii'))[0]) - if bytes(s[-count::], 'ascii') == count * struct.pack('B', count): + count = s[-1] + if s[-count::] == count * struct.pack('B', count): return s[:-count] return s @@ -116,6 +116,7 @@ def decode_memo(priv, pub, nonce, message): " TODO, verify checksum " message = cleartext[4:] try: - return _unpad(message.decode('utf8'), 16) + message = _unpad(message, 16) except Exception as e: raise ValueError(message) + return message.decode('utf8') \ No newline at end of file diff --git a/tests/test_memo.py b/tests/test_memo.py index 9a09f574..a31456fe 100644 --- a/tests/test_memo.py +++ b/tests/test_memo.py @@ -87,8 +87,8 @@ class Testcases(unittest.TestCase): def test_padding(self): for l in range(0, 255): s = bytes(l * chr(l), 'utf-8') - padded = _pad(s, 16).decode('utf-8') - self.assertEqual(s.decode('utf-8'), _unpad(padded, 16)) + padded = _pad(s, 16) + self.assertEqual(s, _unpad(padded, 16)) def test_decrypt(self): for memo in test_cases: