From: Eduardo Robles Elvira Date: Fri, 19 Jul 2013 07:48:30 +0000 (+0200) Subject: specifying key_length in bits instead of bytes X-Git-Tag: v2.2~156 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=3025603bf58c011c8fb51f4cdd76bb5380a22ef3;p=python-delta-tar specifying key_length in bits instead of bytes --- diff --git a/deltatar/aescrypto.py b/deltatar/aescrypto.py index 973400e..5ae2b06 100644 --- a/deltatar/aescrypto.py +++ b/deltatar/aescrypto.py @@ -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 diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 849942e..1734c7b 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -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")