accept external counter in crypto.py
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Thu, 6 Apr 2017 12:34:20 +0000 (14:34 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:08 +0000 (13:34 +0200)
Required when encrypting an auxiliary file of type info.

deltatar/crypto.py

index 4ca4e10..e6374ad 100755 (executable)
@@ -245,6 +245,7 @@ def hex_spaced_of_bytes (b):
                        for c1, c2 in zip (b[0::2], b[1::2]) ]) \
          + (len (b) | 1 == len (b) and " %.2x" % b[-1] or "") # odd lengths
 
+
 hdr_dump = hex_spaced_of_bytes
 
 
@@ -465,9 +466,9 @@ class Encrypt (Crypto):
         return struct.pack(FMT_I2N_IV, self.pfx [-1], self.cnt)
 
 
-    def next (self, filename, version, nacl):
+    def next (self, filename, version, nacl, counter=None):
         self.curobj = (filename, version, nacl or self.nacl)
-        self.set_object_counter (self.cnt + 1)
+        self.set_object_counter (counter if counter is not None else self.cnt + 1)
         self.iv = self.iv_make ()
 
         if self.paramenc == "aes-gcm":
@@ -590,7 +591,7 @@ class PDTDecryptionError (Exception):
 
 
 def noise (*a, **b):
-    print (file=sys.stderr, *a, *b)
+    print (file=sys.stderr, *a, **b)
 
 
 def depdtcrypt (pw, ins, outs):