From 4bc84bc0318ce9889be826638ab52f8aec334d22 Mon Sep 17 00:00:00 2001 From: larabr <7375870+larabr@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:15:50 +0200 Subject: [PATCH] Make `ARGON2_WASM_MEMORY_THRESHOLD_RELOAD` a class property To be able to change its value --- .eslintrc.js | 2 +- openpgp.d.ts | 1 + src/type/s2k/argon2.js | 9 ++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 6a58bb27a0..7e0698b6dd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { 'extends': 'airbnb-base', 'parserOptions': { - 'ecmaVersion': 11, + 'ecmaVersion': 2022, 'sourceType': 'module' }, diff --git a/openpgp.d.ts b/openpgp.d.ts index 6ec283b063..fc4a83cec4 100644 --- a/openpgp.d.ts +++ b/openpgp.d.ts @@ -926,6 +926,7 @@ export namespace enums { export declare class Argon2S2K { static reloadWasmModule(): void; + static ARGON2_WASM_MEMORY_THRESHOLD_RELOAD: number; constructor(config: Config); salt: Uint8Array; /** @throws Argon2OutOfMemoryError */ diff --git a/src/type/s2k/argon2.js b/src/type/s2k/argon2.js index 4a1a822454..fcd5fc74fd 100644 --- a/src/type/s2k/argon2.js +++ b/src/type/s2k/argon2.js @@ -22,10 +22,13 @@ export class Argon2OutOfMemoryError extends Error { // cache argon wasm module let loadArgonWasmModule; let argon2Promise; -// reload wasm module above this treshold, to deallocated used memory -const ARGON2_WASM_MEMORY_THRESHOLD_RELOAD = 2 << 19; class Argon2S2K { + /** + * Reload wasm module above this treshold, to deallocated used memory + */ + static ARGON2_WASM_MEMORY_THRESHOLD_RELOAD = 2 << 19; + static reloadWasmModule() { if (!loadArgonWasmModule) return; @@ -121,7 +124,7 @@ class Argon2S2K { }); // a lot of memory was used, reload to deallocate - if (decodedM > ARGON2_WASM_MEMORY_THRESHOLD_RELOAD) { + if (decodedM > Argon2S2K.ARGON2_WASM_MEMORY_THRESHOLD_RELOAD) { Argon2S2K.reloadWasmModule(); } return hash;