add support for PDT encryption to run_benchmark.py
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Thu, 23 Apr 2020 11:53:55 +0000 (13:53 +0200)
committerPhilipp Gesang <philipp.gesang@intra2net.com>
Fri, 24 Apr 2020 06:55:25 +0000 (08:55 +0200)
The script was still expecting the encryption to be handled in
the pre-crypto.py fashion.

Paths need some preparing as well so we can inject a deltatar
from arbitrary locations; the $DELTATAR environment variable
is used for this.

deltatar/__init__.py
testing/run_benchmark.py

index 8d1c8b6..3d91d64 100644 (file)
@@ -1 +1,3 @@
+from . import crypto 
+from . import tarfile 
+from . import deltatar 
index d7a0083..18114d1 100755 (executable)
@@ -25,6 +25,7 @@ import zlib
 import fnmatch
 import cProfile
 import io
+import binascii
 import pstats
 
 
@@ -88,21 +89,44 @@ def main(args = None):
 
 def test_tarfile(res, compression_level=9, path='source_dir', tarmode="w:gz"):
     '''
-    Test that creates a tarfile called test_tarfile.tar.gz
+    Test that creates a tarfile called test_tarfile.tar.gz from a directory.
     '''
+    encryptor = None
+    dstfile = "test_tarfile.tar.gz"
+
     if res == 'delta-tarfile':
-        deltatar = os.path.abspath("../deltatar")
         import sys
-        sys.path.append("..")
-        from deltatar import tarfile as TarFile
+        # need to fix up the path before we can load a module explicitly
+        dtarpath = os.getenv ("DELTATAR")
+        if dtarpath is not None:
+            sys.path.append (dtarpath)
+
+        try: 
+            from deltatar import tarfile as TarFile
+            from deltatar import crypto
+        except ImportError:
+            raise Exception ("location of deltatar not found; "
+                             "set $DELTATAR to provide an explicit path")
+
+        if tarmode.endswith (".pdtcrypt"):
+            dstfile   = dstfile + ".pdtcrypt"
+            tarmode   = tarmode.rstrip (".pdtcrypt")
+            encryptor = crypto.Encrypt (password="test1234",
+                                        nacl=binascii.unhexlify(b"0011223344556677"
+                                                                b"8899aabbccddeeff"),
+                                        version=1,
+                                        paramversion=1)
+
     elif res == 'tarfile':
         import tarfile as TarFile
 
-    print("creating a tarfile with mode = '%s'" % tarmode)
-    with open('test_tarfile.tar.gz', 'wb') as fo:
-        tar = TarFile.open(mode=tarmode, fileobj=fo,
-                           compresslevel=compression_level)
-        tar.add(path)
+    tar = TarFile.open (dstfile,
+                        mode=tarmode,
+                        concat='#' in tarmode,
+                        encryption=encryptor,
+                        compresslevel=compression_level)
+    tar.add(path)
+
 
 def test_zlib(compression_level=9, path='source_dir', strategy='default',
               BUFSIZE = 16 * 1024):