track encryption state
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Tue, 21 Mar 2017 14:32:32 +0000 (15:32 +0100)
committerPhilipp Gesang <philipp.gesang@intra2net.com>
Tue, 21 Mar 2017 14:32:32 +0000 (15:32 +0100)
deltatar/crypto.py
deltatar/tarfile.py

index 119bfbc..64e62f9 100755 (executable)
@@ -299,6 +299,8 @@ def kdf_by_version (paramversion):
     return partial (fn, params)
 
 
+STATE_DEAD = 0
+STATE_LIVE = 1
 
 class Crypto (object):
     """
@@ -314,6 +316,7 @@ class Crypto (object):
     stats = { "in"  : 0
             , "out" : 0
             , "obj" : 0 }
+    state = STATE_DEAD
 
     def __init__ (self, *al, **akv):
         self.cnt  = 1
@@ -351,6 +354,9 @@ class Crypto (object):
         return self.stats ["obj"], self.stats ["in"], self.stats ["out"]
 
 
+    def currentstate (self): return self.state
+
+
 class Encrypt (Crypto):
 
     curobj = None
@@ -382,6 +388,7 @@ class Encrypt (Crypto):
 
         self.hdrdum = hdr_make_dummy (filename)
         self.stats ["obj"] += 1
+        self.state = STATE_LIVE
         return self.hdrdum
 
 
@@ -396,6 +403,7 @@ class Encrypt (Crypto):
                                    self.ctsize, self.aes.tag)
         if ok is False:
             raise Exception ("XXX error constructing header: %r" % hdr) ## we need to converge on a sensible error handling strategy
+        self.state = STATE_DEAD
         return data, hdr
 
 
@@ -433,6 +441,7 @@ class Decrypt (Crypto):
         ctsize = 0
         ptsize = 0
         self.stats ["obj"] += 1
+        self.state = STATE_LIVE
 
 
     def next_in_source (self, tarinfo, source):
@@ -453,6 +462,7 @@ class Decrypt (Crypto):
         except crypto.cryptography.exceptions.InvalidTag as exn:
             return False, repr (exn)
         self.stats ["out"] += len (data)
+        self.state = STATE_DEAD
         return ret, data
 
 
index 4cc2840..c48c8d6 100644 (file)
@@ -532,6 +532,9 @@ class _Stream:
         if hasattr(self, "closed") and not self.closed:
             self.close()
         #if self.encryption is not None:
+        #    print("crypto: %s"
+        #          % (self.encryption.currentstate () == crypto.STATE_DEAD
+        #                    and "inactive" or "active"))
         #    print("crypto: %d objects handled, %d B in, %d B out"
         #          % self.encryption.counters ())