strip extraneous parameters from decryption handler ctor
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Mon, 10 Apr 2017 09:43:06 +0000 (11:43 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:08 +0000 (13:34 +0200)
Format and parameter version as well as the salt are supplied
from the headers. Decrypting should thus only require the
password and, depending on context, an explicit counter as well
as the list of valid IV fixed parts.

deltatar/crypto.py

index 3e512ba..bcc89b8 100755 (executable)
@@ -446,8 +446,8 @@ class Crypto (object):
         self.next_pfx ()
 
 
-    def set_parameters (self, password, paramversion, nacl=None, counter=None,
-                        nextpfx=None):
+    def set_parameters (self, password, paramversion=None, nacl=None,
+                        counter=None, nextpfx=None):
         if nextpfx is not None:
             self.next_pfx = nextpfx
             self.next_pfx ()
@@ -599,8 +599,7 @@ class Decrypt (Crypto):
 
     tag = None # GCM tag, part of header
 
-    def __init__ (self, password, paramversion=None, nacl=None, counter=None,
-                  fixedparts=None):
+    def __init__ (self, password, counter=None, fixedparts=None):
         # passwort
         if isinstance (password, str) is False:
             raise InvalidParameter ("__init__: password must be a string, not %s"
@@ -608,22 +607,6 @@ class Decrypt (Crypto):
         if len (password) == 0:
             raise InvalidParameter ("__init__: supplied empty password but not "
                                     "permitted for PDT encrypted files")
-        # version
-        if isinstance (version, int) is False:
-            raise InvalidParameter ("__init__: version number must be an "
-                                    "integer, not %s" % type (version))
-        if version < 0:
-            raise InvalidParameter ("__init__: version number must be a "
-                                    "nonnegative integer, not %d" % version)
-        # paramversion
-        if isinstance (paramversion, int) is False:
-            raise InvalidParameter ("__init__: crypto parameter version number "
-                                    "must be an integer, not %s"
-                                    % type (paramversion))
-        if paramversion < 0:
-            raise InvalidParameter ("__init__: crypto parameter version number "
-                                    "must be a nonnegative integer, not %d"
-                                    % paramversion)
         # fixed parts
         if fixedparts is not None:
             if isinstance (fixedparts, list) is False:
@@ -632,8 +615,8 @@ class Decrypt (Crypto):
                                         % type (fixedparts))
             self.fixed = fixedparts
             self.fixed.sort ()
-            super().__init__ (password, paramversion, nacl, counter=counter)
-        super().__init__ (password, paramversion, nacl, counter=counter)
+            super().__init__ (password, counter=counter)
+        super().__init__ (password, counter=counter)
 
 
     def valid_fixed_part (self, iv):