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
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):