瀏覽代碼

Make Crypto.auth python3 compatible

oz123 10 年之前
父節點
當前提交
fef3afcee8
共有 2 個文件被更改,包括 6 次插入3 次删除
  1. 3 1
      pwman/tests/db_tests.py
  2. 3 2
      pwman/util/crypto.py

+ 3 - 1
pwman/tests/db_tests.py

@@ -351,7 +351,9 @@ class CLITests(unittest.TestCase):
 
     def test_do_auth(self):
         crypto = CryptoEngine.get()
-        crypto.auth('12345')
+        rv = crypto.auth('12345')
+        self.assertIs(rv, None)
+        self.assertRaises(CryptoBadKeyException, crypto.auth, 'WRONG')
 
     def test_do_clear(self):
         self.tester.cli.do_clear('')

+ 3 - 2
pwman/util/crypto.py

@@ -179,9 +179,10 @@ class CryptoEngine(object):
         authenticate using a given key
         """
         tmpcipher = self._getcipher_real(key, self._algo)
-        plainkey = tmpcipher.decrypt(str(self._keycrypted).decode('base64'))
+        s = base64.b64decode(self._keycrypted)
+        plainkey = tmpcipher.decrypt(s)
         key = self._retrievedata(plainkey)
-        key = str(key).decode('base64')
+        key = base64.b64decode(str(key))
         self._cipher = self._getcipher_real(key, self._algo)
 
     def encrypt(self, obj):