def hdr_read_stream (instr):
data = instr.read(I2N_HDR_SIZE)
- if len (data) != FMT_I2N_HDR:
- return False, "error reading from [%r]: expected %d B, received %d" \
+ if len (data) != I2N_HDR_SIZE:
+ return False, "error reading from [%r]: expected %d B, received %d B" \
% (instr, I2N_HDR_SIZE, len (data))
- return True, hdr_read (data)
+ return hdr_read (data)
def hdr_from_params (version, paramversion, nacl, iv, ctsize, tag):
self.pfx = os.urandom(8)
- def set_parameters_from_header (self, hdr):
- self.password = password
- self.nacl = nacl
- self.paramversion = paramversion
- self.pfx = pfx
-
-
def process (self, buf):
if self.aes is not None:
return self.aes.update (buf)
pfx = None
password = None
tag = None # GCM tag, part of header
+ ctsize = -1
+ ptsize = -1
def __init__ (self, password, paramversion=None, nacl=None):
if paramversion is not None \
# XXX figure out what we want for AAD. Filename (not known to stream)?
# Size?
#self.aes.authenticate_additional_data (str.encode (aad))
+ ctsize = 0
+ ptsize = 0
def next_in_source (self, tarinfo, source):
return self.next(hdr)
- def done (self, tag):
+ def done (self):
return self.aes.finalize_with_tag (self.tag)
+ def process (self, buf):
+ self.ctsize += len (buf)
+ data = super().process (buf)
+ self.ptsize += len (data)
+ return data
+
+
###############################################################################
## freestanding invocation
###############################################################################