specifying key_length in bits instead of bytes
authorEduardo Robles Elvira <edulix@wadobo.com>
Fri, 19 Jul 2013 07:48:30 +0000 (09:48 +0200)
committerEduardo Robles Elvira <edulix@wadobo.com>
Fri, 19 Jul 2013 07:48:30 +0000 (09:48 +0200)
deltatar/aescrypto.py
deltatar/tarfile.py

index 973400e..5ae2b06 100644 (file)
@@ -35,10 +35,12 @@ class AESCrypt:
     This class provides a simple method to encrypt and decrypt text using
     AES.
     '''
-    def __init__(self, password, salt='', key_length=16):
+    def __init__(self, password, salt='', key_length=128):
         self.bs = AES.block_size
         self.mode = AES.MODE_CBC
-        self.key_length = key_length
+        if key_length not in [128, 256]:
+            raise Exception('Invalid key_length, only 128 and 256 allowed')
+        self.key_length = key_length/8
         self.buf = ''
         if salt:
             self.salt = salt
index 849942e..1734c7b 100644 (file)
@@ -401,7 +401,7 @@ class _Stream:
 
     def __init__(self, name, mode, comptype, fileobj, bufsize,
                  concat_stream=False, enctype='', password="",
-                 key_length=16):
+                 key_length=128):
         """Construct a _Stream object.
         """
         self._extfileobj = True
@@ -1902,7 +1902,7 @@ class TarFile(object):
             password = ''
             # if not enctype there's no encryption
             enctype = ''
-            key_length = 16
+            key_length = 128
 
             if filemode not in "rw":
                 raise ValueError("mode must be 'r' or 'w'")
@@ -1915,7 +1915,7 @@ class TarFile(object):
                 comptype, enctype = comptype.split(".", 1)
                 kl = enctype[3:]
                 enctype = enctype[:3]
-                key_length = 16 if kl == '128' else 32
+                key_length = 128 if kl == '128' else 256
                 password = kwargs.get('password', '')
                 if not password:
                     raise ValueError("you should give a password for encryption")