]> git.datanom.net - securemail.git/blobdiff - cryptonize.py
Make backwards compatible with nacl 1.0.x
[securemail.git] / cryptonize.py
index d4b511596e803b308995bf7c472b81a929054ae7..9c1b02fdcfd17b8f179dc4228b98b0a421befe87 100644 (file)
@@ -33,8 +33,6 @@ class Cryptonize:
         skey = self.sanitize_key(key)
         box = SecretBox(skey)
         if NACL_VERSION < "1.1.0":
-            from nacl.utils import random
-            from nacl.public import SecretBox
             nonce = random(SecretBox.NONCE_SIZE)
             cipher = box.encrypt(plain, nonce)
         else:
@@ -53,7 +51,11 @@ class Cryptonize:
         
     def asymmetric_encrypt(self, privkey, pubkey, plain):
         box = Box(privkey, pubkey)
-        cipher = box.encrypt(plain)
+        if NACL_VERSION < "1.1.0":
+            nonce = random(Box.NONCE_SIZE)
+            cipher = box.encrypt(plain, nonce)
+        else:
+            cipher = box.encrypt(plain)
         box = None
         
         return cipher
This page took 0.028121 seconds and 5 git commands to generate.