From a636e333a4d86c44e335fc3cc23bc2da93d57a1e Mon Sep 17 00:00:00 2001 From: seebees Date: Tue, 4 May 2021 10:00:59 -0700 Subject: [PATCH] fix: decoded encryption context is frozen If the encryption context is empty it should still be frozen. --- modules/serialize/src/decode_encryption_context.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/serialize/src/decode_encryption_context.ts b/modules/serialize/src/decode_encryption_context.ts index ada22117b..675505ba3 100644 --- a/modules/serialize/src/decode_encryption_context.ts +++ b/modules/serialize/src/decode_encryption_context.ts @@ -23,11 +23,13 @@ export function decodeEncryptionContextFactory( * Exported for testing. Used by deserializeMessageHeader to compose a complete solution. * @param encodedEncryptionContext Uint8Array */ - function decodeEncryptionContext(encodedEncryptionContext: Uint8Array) { + function decodeEncryptionContext( + encodedEncryptionContext: Uint8Array + ): Readonly { const encryptionContext: EncryptionContext = Object.create(null) /* Check for early return (Postcondition): The case of 0 length is defined as an empty object. */ if (!encodedEncryptionContext.byteLength) { - return encryptionContext + return Object.freeze(encryptionContext) } /* Uint8Array is a view on top of the underlying ArrayBuffer. * This means that raw underlying memory stored in the ArrayBuffer