From 07a4d280b1132ab2e5ccc6b98155c02893894aa2 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 21 Mar 2017 15:32:32 +0100 Subject: [PATCH] track encryption state --- deltatar/crypto.py | 10 ++++++++++ deltatar/tarfile.py | 3 +++ 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/deltatar/crypto.py b/deltatar/crypto.py index 119bfbc..64e62f9 100755 --- a/deltatar/crypto.py +++ b/deltatar/crypto.py @@ -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 diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 4cc2840..c48c8d6 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -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 ()) -- 1.7.1