Skip to content

Commit ff3a7ad

Browse files
committed
Add failing test for unicode string encryption
1 parent 91bf921 commit ff3a7ad

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/unit/test_secret.py

+20
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,23 @@ def test_secret(self):
2020
clear3 = box.decrypt(ctxt2)
2121
self.assertEqual(clear3, msg)
2222

23+
def test_unicode_issues(self):
24+
msg = u'Unicode string'
25+
box = libnacl.secret.SecretBox()
26+
27+
# Encrypting a unicode string (in py2) should
28+
# probable assert, but instead it encryptes zeros,
29+
# perhaps the high bytes in UCS-16?
30+
ctxt = box.encrypt(msg)
31+
self.assertNotEqual(msg, ctxt)
32+
33+
box2 = libnacl.secret.SecretBox(box.sk)
34+
clear1 = box.decrypt(ctxt)
35+
36+
self.assertEqual(msg, clear1)
37+
clear2 = box2.decrypt(ctxt)
38+
39+
self.assertEqual(clear1, clear2)
40+
ctxt2 = box2.encrypt(msg)
41+
clear3 = box.decrypt(ctxt2)
42+
self.assertEqual(clear3, msg)

0 commit comments

Comments
 (0)