summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2022-03-18 13:25:00 +0100
committerMaxime “pep” Buquet <pep@bouah.net>2022-03-19 10:31:34 +0100
commitc1aeab328b8c25d67d29ec7587534e7701007858 (patch)
treef77fff3a0f7c2c09fa36273c6cb39a981b971737
parent51644e301bdcdc373871e3a6e282a3df5c6d61d1 (diff)
downloadslixmpp-c1aeab328b8c25d67d29ec7587534e7701007858.tar.gz
slixmpp-c1aeab328b8c25d67d29ec7587534e7701007858.tar.bz2
slixmpp-c1aeab328b8c25d67d29ec7587534e7701007858.tar.xz
slixmpp-c1aeab328b8c25d67d29ec7587534e7701007858.zip
xep_0454: use streaming API from CipherContext
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
-rw-r--r--slixmpp/plugins/xep_0454/__init__.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/slixmpp/plugins/xep_0454/__init__.py b/slixmpp/plugins/xep_0454/__init__.py
index 2d3cb8f6..9e9c3b02 100644
--- a/slixmpp/plugins/xep_0454/__init__.py
+++ b/slixmpp/plugins/xep_0454/__init__.py
@@ -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()
-
- payload = aes_gcm.update(plain) + aes_gcm.tag + aes_gcm.finalize()
+ if input_file is None:
+ input_file = open(filename, 'rb')
+
+ 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)