From 99dad5525028d89f6ef0ff91e2de3b1b251df6da Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Sun, 12 Aug 2018 01:11:52 +0200 Subject: [PATCH] Make backwards compatible with nacl 1.0.x --- user.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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): -- 2.39.2