permit setting crypto.py parameter version via deltatar ctor
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Fri, 21 Apr 2017 07:39:02 +0000 (09:39 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:08 +0000 (13:34 +0200)
Introduce an optional argument to request a specific crypto
parameter version when invoking Deltatar. This isn’t of much
use ATM since only the one version is implemented, but it’s
handy for testing nonetheless.

deltatar/deltatar.py

index b9eae99..ac702e3 100644 (file)
@@ -90,6 +90,10 @@ class DeltaTar(object):
     # used together with aes modes to encrypt and decrypt backups.
     password = None
 
+    # parameter version to use when encrypting; note that this has no effect
+    # on decryption since the required settings are determined from the headers
+    crypto_paramversion = None
+
     # when encrypting or decrypting, this holds crypto handler; created before
     # establishing the Tarfile stream iff a password is supplied.
     crypto_ctx = None
@@ -146,6 +150,7 @@ class DeltaTar(object):
 
     def __init__(self, excluded_files=[], included_files=[],
                  filter_func=None, mode="", password=None,
+                 crypto_paramversion=DELTATAR_PARAMETER_VERSION,
                  logger=None, index_mode=None, index_name_func=None,
                  volume_name_func=None):
         '''
@@ -182,6 +187,10 @@ class DeltaTar(object):
         - password: used to encrypt and decrypt backups. Encryption will be
           enabled automatically if a password is supplied.
 
+        - crypto_paramversion: optionally request encryption conforming to
+          a specific parameter version. Defaults to the standard PDT value
+          which as of 2017 is the only one available.
+
         - logger: python logger object. Optional.
 
         - index_mode:  specifies the index mode in the same format as @param
@@ -220,6 +229,10 @@ class DeltaTar(object):
         if password is not None:
             self.password = password
 
+        if crypto_paramversion is not None:
+            self.crypto_paramversion = crypto_paramversion
+
+
         # generate index_mode
         if index_mode is None:
             index_mode = ''
@@ -596,7 +609,7 @@ class DeltaTar(object):
             self.crypto_ctx = \
                     crypto.Encrypt (self.password,
                                     version=DELTATAR_HEADER_VERSION,
-                                    paramversion=DELTATAR_PARAMETER_VERSION)
+                                    paramversion=self.crypto_paramversion)
 
         # some initialization
         self.vol_no = 0
@@ -767,7 +780,7 @@ class DeltaTar(object):
             self.crypto_ctx = \
                     crypto.Encrypt (self.password,
                                     version=DELTATAR_HEADER_VERSION,
-                                    paramversion=DELTATAR_PARAMETER_VERSION)
+                                    paramversion=self.crypto_paramversion)
         # some initialization
         self.vol_no = 0