xep_0454: use streaming API from CipherContext
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
51644e301b
commit
c1aeab328b
1 changed files with 11 additions and 7 deletions
|
@ -57,14 +57,18 @@ class XEP_0454(BasePlugin):
|
|||
modes.GCM(aes_gcm_iv),
|
||||
).encryptor()
|
||||
|
||||
# TODO: use streaming API from CipherContext
|
||||
if input_file:
|
||||
plain = input_file.read()
|
||||
else:
|
||||
with filename.open(mode='rb') as file:
|
||||
plain = file.read()
|
||||
if input_file is None:
|
||||
input_file = open(filename, 'rb')
|
||||
|
||||
payload = aes_gcm.update(plain) + aes_gcm.tag + aes_gcm.finalize()
|
||||
payload = b''
|
||||
while True:
|
||||
buf = input_file.read(4096)
|
||||
if not buf:
|
||||
break
|
||||
payload += aes_gcm.update(buf)
|
||||
|
||||
aes_gcm.finalize()
|
||||
payload += aes_gcm.tag
|
||||
fragment = aes_gcm_iv.hex() + aes_gcm_key.hex()
|
||||
return (payload, fragment)
|
||||
|
||||
|
|
Loading…
Reference in a new issue