]> git.datanom.net - securemail.git/commitdiff
Make backwards compatible with nacl 1.0.x
authorMichael Rasmussen <mir@datanom.net>
Sat, 11 Aug 2018 23:11:52 +0000 (01:11 +0200)
committerMichael Rasmussen <mir@datanom.net>
Sat, 11 Aug 2018 23:11:52 +0000 (01:11 +0200)
user.py

diff --git a/user.py b/user.py
index 64673c7c7ce58f5484d271cb7f85c9f5623221c3..fd3d39724e34770b1a0551a5b8797688789f9619 100644 (file)
--- a/user.py
+++ b/user.py
@@ -21,6 +21,7 @@ import pickle
 from db import DBInterface as DBI
 from cryptonize import Cryptonize
 from nacl.public import PublicKey
+from nacl import __version__ as NACL_VERSION
 
 class NoSuchUser(Exception):
     pass
@@ -37,7 +38,13 @@ class User:
 
     def store(self, key):
         crypto = Cryptonize()
-        cipher = crypto.symmetric_encrypt(key, pickle.dumps(self))
+        if NACL_VERSION < "1.1.0":
+            from nacl.utils import random
+            from nacl.public import SecretBox
+            nonce = random(SecretBox.NONCE_SIZE)
+            cipher = crypto.symmetric_encrypt(key, pickle.dumps(self), nonce)
+        else:
+            cipher = crypto.symmetric_encrypt(key, pickle.dumps(self))
         DBI.store_user(crypto.generate_hash(key), cipher)
 
     def load(self, key):
This page took 0.066844 seconds and 5 git commands to generate.