diff options
author | Jack Lloyd <[email protected]> | 2018-08-11 18:11:56 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-08-11 18:11:56 -0400 |
commit | 24963a27f6f5e2235f00ef7463f039bceac548b3 (patch) | |
tree | c32e9c16277325ae78b774ba6b10a9c79faa28cb /src | |
parent | cb05f9c9938434c0c56122addd94015e7df38b19 (diff) |
Fix Python2 problem
Diffstat (limited to 'src')
-rwxr-xr-x | src/python/botan2.py | 8 | ||||
-rw-r--r-- | src/scripts/test_python.py | 1 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/python/botan2.py b/src/python/botan2.py index 617efa887..209805a66 100755 --- a/src/python/botan2.py +++ b/src/python/botan2.py @@ -395,6 +395,12 @@ def _ctype_str(s): else: return s.encode('utf-8') +def _ctype_to_str(s): + if version_info[0] < 3: + return s.encode('utf-8') + else: + return s.decode('utf-8') + def _ctype_bits(s): if version_info[0] < 3: if isinstance(s, str): @@ -608,7 +614,7 @@ def bcrypt(passwd, rng_instance, work_factor=10): b = out.raw[0:int(out_len.value)-1] if b[-1] == '\x00': b = b[:-1] - return b.decode('ascii') + return _ctype_to_str(b) def check_bcrypt(passwd, passwd_hash): rc = botan.botan_bcrypt_is_valid(_ctype_str(passwd), _ctype_str(passwd_hash)) diff --git a/src/scripts/test_python.py b/src/scripts/test_python.py index 34233f6f9..4bd0085ab 100644 --- a/src/scripts/test_python.py +++ b/src/scripts/test_python.py @@ -60,6 +60,7 @@ class BotanPythonTests(unittest.TestCase): def test_bcrypt(self): r = botan2.rng() phash = botan2.bcrypt('testing', r) + self.assertTrue(isinstance(phash, str)) self.assertTrue(phash.startswith("$2a$")) self.assertTrue(botan2.check_bcrypt('testing', phash)) |