From c289bcd0978d1c577fa8ddc801eee7c95585f095 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 11 Nov 2020 10:46:37 +0100 Subject: [PATCH] return blob from encryptAttachment --- src/matrix/e2ee/attachment.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/matrix/e2ee/attachment.js b/src/matrix/e2ee/attachment.js index cea91cfa..02a051ed 100644 --- a/src/matrix/e2ee/attachment.js +++ b/src/matrix/e2ee/attachment.js @@ -57,13 +57,15 @@ export async function decryptAttachment(crypto, ciphertextBuffer, info) { return decryptedBuffer; } -export async function encryptAttachment(crypto, data) { +export async function encryptAttachment(platform, blob) { + const {crypto} = platform; const iv = await crypto.aes.generateIV(); const key = await crypto.aes.generateKey("jwk", 256); - const ciphertext = await crypto.aes.encryptCTR({key, iv, data}); + const buffer = await blob.readAsBuffer(); + const ciphertext = await crypto.aes.encryptCTR({key, iv, data: buffer}); const digest = await crypto.digest("SHA-256", ciphertext); return { - data: ciphertext, + blob: platform.createBlob(ciphertext, blob.mimeType), info: { v: "v2", key,