From: Michael Rasmussen Date: Sat, 11 Aug 2018 23:11:52 +0000 (+0200) Subject: Make backwards compatible with nacl 1.0.x X-Git-Url: http://git.datanom.net/securemail.git/commitdiff_plain/99dad5525028d89f6ef0ff91e2de3b1b251df6da Make backwards compatible with nacl 1.0.x --- diff --git a/user.py b/user.py index 64673c7..fd3d397 100644 --- 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):