diff --git a/.eslintrc.js b/.eslintrc.js index 6a58bb27a..7e0698b6d 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 6ec283b06..fc4a83cec 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 4a1a82245..bdda332d4 100644 --- a/src/type/s2k/argon2.js +++ b/src/type/s2k/argon2.js @@ -23,9 +23,18 @@ export class Argon2OutOfMemoryError extends Error { let loadArgonWasmModule; let argon2Promise; // reload wasm module above this treshold, to deallocated used memory -const ARGON2_WASM_MEMORY_THRESHOLD_RELOAD = 2 << 19; +// (cannot be declared as a simple `static` field as its not supported by Safari 14) +let ARGON2_WASM_MEMORY_THRESHOLD_RELOAD = 2 << 19; class Argon2S2K { + static get ARGON2_WASM_MEMORY_THRESHOLD_RELOAD() { + return ARGON2_WASM_MEMORY_THRESHOLD_RELOAD; + } + + static set ARGON2_WASM_MEMORY_THRESHOLD_RELOAD(memoryThreshold) { + ARGON2_WASM_MEMORY_THRESHOLD_RELOAD = memoryThreshold; + } + static reloadWasmModule() { if (!loadArgonWasmModule) return; @@ -121,7 +130,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;