From b07633d35509b42a6ec337a9d9bc5228a077d6aa Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 24 Apr 2017 12:06:46 +0200 Subject: [PATCH] use crypto.py to split test archive in test_encryption.py This again verifies individual decryptability of objects in the PDT archive. --- deltatar/crypto.py | 13 +++++++++++-- testing/test_encryption.py | 15 +++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/deltatar/crypto.py b/deltatar/crypto.py index 3339878..cec61e0 100755 --- a/deltatar/crypto.py +++ b/deltatar/crypto.py @@ -757,6 +757,7 @@ PDTCRYPT_SPLITNAME = "pdtcrypt-object-%d.bin" PDTCRYPT_VERBOSE = False PDTCRYPT_STRICTIVS = False +PDTCRYPT_OVERWRITE = False PDTCRYPT_BLOCKSIZE = 1 << 12 PDTCRYPT_SINK = 0 PDTCRYPT_SOURCE = 1 @@ -843,8 +844,12 @@ def depdtcrypt (mode, pw, ins, outs): assert total_obj > 0 fname = PDTCRYPT_SPLITNAME % total_obj try: - outfd = os.open (fname, os.O_CREAT | os.O_EXCL | os.O_WRONLY, - 0o600, dir_fd=outs) + oflags = os.O_CREAT | os.O_WRONLY + if PDTCRYPT_OVERWRITE is True: + oflags |= os.O_TRUNC + else: + oflags |= os.O_EXCL + outfd = os.open (fname, oflags, 0o600, dir_fd=outs) if PDTCRYPT_VERBOSE is True: noise ("PDT: new output file %s → %d" % (fname, outfd)) except FileExistsError as exn: @@ -1039,6 +1044,10 @@ def parse_argv (argv): elif arg in [ "-o", "--out", "--dest", "--sink" ]: outsspec = next (argvi) if PDTCRYPT_VERBOSE is True: noise ("PDT: decrypt to %s" % outsspec) + elif arg in [ "-f", "--force" ]: + global PDTCRYPT_OVERWRITE + PDTCRYPT_OVERWRITE = True + if PDTCRYPT_VERBOSE is True: noise ("PDT: overwrite existing files") elif arg in [ "-S", "--split" ]: mode |= PDTCRYPT_SPLIT if PDTCRYPT_VERBOSE is True: noise ("PDT: split files") diff --git a/testing/test_encryption.py b/testing/test_encryption.py index 5088ab2..9dafdc1 100644 --- a/testing/test_encryption.py +++ b/testing/test_encryption.py @@ -85,8 +85,8 @@ class EncryptionTest(BaseTest): def test_cli_multiple_files_decrypt(self): """ Create a tar file with multiple files inside, using concat - compression and encryption mode. Then decrypt with ``crypto.py``, - decompress it with zcat and untar it with gnu tar. + compression and encryption mode. Then decrypt and split with + ``crypto.py``, decompress it with zcat and untar it with gnu tar. """ # create sample data @@ -115,11 +115,14 @@ class EncryptionTest(BaseTest): os.unlink(k) assert os.path.exists("sample.tar.gz.pdtcrypt") - ret = os.system("python3 -s ./deltatar/crypto.py key sample.tar.gz") + ret = os.system("python3 -s ./deltatar/crypto.py key --split " + "-i sample.tar.gz.pdtcrypt -o .") assert ret == 0 - assert os.path.exists("sample.tar.gz") - os.system("zcat sample.tar.gz 2>/dev/null > sample.tar") - os.system("tar xf sample.tar") + for i in range (len (hash)): + fname = "pdtcrypt-object-%d.bin" % (i + 1) + assert os.path.exists(fname) + os.system("zcat '%s' 2>/dev/null > sample.tar" % fname) + os.system("tar xf sample.tar") for key, value in hash.items(): assert os.path.exists(key) -- 1.7.1