From c1cafafc9ca042f5acd7c81994ad1dadd4a5962b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Iv=C3=A1n=20Vieitez=20Parra?= <3857362+corrideat@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:49:47 +0100 Subject: [PATCH] Move static buffers into getters to avoid side-effects --- package.json | 2 +- src/encodings.ts | 46 ++++++++++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 1fb0943..e7279b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@exact-realty/rfc8188", - "version": "1.0.1", + "version": "1.0.2", "description": "An implementation of RFC 8188 (encrypted content-encoding for HTTP)", "type": "module", "main": "dist/index.cjs", diff --git a/src/encodings.ts b/src/encodings.ts index a091a5a..3d44163 100644 --- a/src/encodings.ts +++ b/src/encodings.ts @@ -28,16 +28,21 @@ export const aes128gcm: Readonly = { ['length']: 128, }, // The literal `Content-Encoding: aes128gcm\x00` - cek_info: new Uint8Array([ - 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x45, 0x6e, 0x63, 0x6f, - 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, - 0x67, 0x63, 0x6d, 0x00, - ]), + get cek_info() { + return new Uint8Array([ + 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x45, 0x6e, 0x63, + 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x61, 0x65, 0x73, 0x31, + 0x32, 0x38, 0x67, 0x63, 0x6d, 0x00, + ]); + }, // The literal `Content-Encoding: nonce\x00` - nonce_info: new Uint8Array([ - 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x45, 0x6e, 0x63, 0x6f, - 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x00, - ]), + get nonce_info() { + return new Uint8Array([ + 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x45, 0x6e, 0x63, + 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x6e, 0x6f, 0x6e, 0x63, + 0x65, 0x00, + ]); + }, block_size: 16, tag_length: 16, nonce_length: 12, @@ -50,16 +55,21 @@ export const aes256gcm: Readonly = { ['length']: 256, }, // The literal `Content-Encoding: aes256gcm\x00` - cek_info: new Uint8Array([ - 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x45, 0x6e, 0x63, 0x6f, - 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, - 0x67, 0x63, 0x6d, 0x00, - ]), + get cek_info() { + return new Uint8Array([ + 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x45, 0x6e, 0x63, + 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x61, 0x65, 0x73, 0x32, + 0x35, 0x36, 0x67, 0x63, 0x6d, 0x00, + ]); + }, // The literal `Content-Encoding: nonce\x00` - nonce_info: new Uint8Array([ - 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x45, 0x6e, 0x63, 0x6f, - 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x00, - ]), + get nonce_info() { + return new Uint8Array([ + 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x45, 0x6e, 0x63, + 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x6e, 0x6f, 0x6e, 0x63, + 0x65, 0x00, + ]); + }, block_size: 16, tag_length: 16, nonce_length: 12,