cnt = None
iv = None
password = None
+ stats = { "in" : 0
+ , "out" : 0
+ , "obj" : 0 }
def __init__ (self, *al, **akv):
self.cnt = 1
def process (self, buf):
if self.aes is not None:
- return self.aes.update (buf)
- # this branch is taken when .close() is called on the fileobj
+ self.stats ["in"] += len (buf)
+ out = self.aes.update (buf)
+ self.stats ["out"] += len (out)
+ return out
return b""
+ def counters (self):
+ return self.stats ["obj"], self.stats ["in"], self.stats ["out"]
+
+
class Encrypt (Crypto):
curobj = None
#self.aes.authenticate_additional_data (str.encode (aad))
self.hdrdum = hdr_make_dummy (filename)
+ self.stats ["obj"] += 1
return self.hdrdum
if cmpdata != self.hdrdum:
raise Exception ("XXX bad sync for writing header") ## we need to converge on a sensible error handling strategy
data = self.aes.finalize ()
+ self.stats ["out"] += len (data)
self.ctsize += len (data)
(filename, version, paramversion, nacl) = self.curobj
ok, hdr = hdr_from_params (version, paramversion, nacl, self.iv,
#self.aes.authenticate_additional_data (str.encode (aad))
ctsize = 0
ptsize = 0
+ self.stats ["obj"] += 1
def next_in_source (self, tarinfo, source):
def done (self, tag=None):
+ data = b""
try:
if tag is None:
- return True, self.aes.finalize ()
+ ret, data = True, self.aes.finalize ()
else:
- return self.aes.finalize_with_tag (self.tag)
+ ret, data = self.aes.finalize_with_tag (self.tag)
except crypto.cryptography.exceptions.InvalidTag as exn:
return False, repr (exn)
+ self.stats ["out"] += len (data)
+ return ret, data
def process (self, buf):
def __del__(self):
if hasattr(self, "closed") and not self.closed:
self.close()
+ #if self.encryption is not None:
+ # print("crypto: %d objects handled, %d B in, %d B out"
+ # % self.encryption.counters ())
def _init_write_encrypt (self, entry=None):