]> git.datanom.net - securemail.git/blobdiff - cryptonize.py
Make backwards compatible with nacl 1.0.x
[securemail.git] / cryptonize.py
index d375f2300b07b09d3299b9a783e6fc8e802fb133..d4b511596e803b308995bf7c472b81a929054ae7 100644 (file)
@@ -17,6 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with SecureMail.  If not, see <https://www.gnu.org/licenses/>.
 
+from nacl import __version__ as NACL_VERSION
 from nacl.secret import SecretBox
 from nacl.public import PrivateKey, Box
 from nacl.utils import random, EncryptedMessage
@@ -31,7 +32,13 @@ class Cryptonize:
     def symmetric_encrypt(self, key, plain):
         skey = self.sanitize_key(key)
         box = SecretBox(skey)
-        cipher = box.encrypt(plain)
+        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:
+            cipher = box.encrypt(plain)
         box = skey = None
         
         return cipher
This page took 0.165082 seconds and 5 git commands to generate.