New attachment storage system

This commit is contained in:
Fedor Indutny 2024-07-11 12:44:09 -07:00 committed by GitHub
parent 273e1ccb15
commit 28664a606f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
161 changed files with 2418 additions and 1562 deletions

View file

@ -11,7 +11,10 @@ export const MAC_KEY_SIZE = 32;
export const MAC_SIZE = 32;
export function appendMacStream(macKey: Uint8Array): Duplex {
export function appendMacStream(
macKey: Uint8Array,
onMac?: (mac: Uint8Array) => undefined
): Duplex {
if (macKey.byteLength !== MAC_KEY_SIZE) {
throw new Error('appendMacStream: invalid macKey length');
}
@ -28,7 +31,9 @@ export function appendMacStream(macKey: Uint8Array): Duplex {
},
flush(callback) {
try {
callback(null, hmac.digest());
const mac = hmac.digest();
onMac?.(mac);
callback(null, mac);
} catch (error) {
callback(error);
}