Skip to content

Commit

Permalink
Make ARGON2_WASM_MEMORY_THRESHOLD_RELOAD a static class property
Browse files Browse the repository at this point in the history
To be able to change its value
  • Loading branch information
larabr committed Apr 11, 2024
1 parent 5c98c7f commit babcc20
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
'extends': 'airbnb-base',
'parserOptions': {
'ecmaVersion': 11,
'ecmaVersion': 2022,
'sourceType': 'module'
},

Expand Down
1 change: 1 addition & 0 deletions openpgp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
13 changes: 11 additions & 2 deletions src/type/s2k/argon2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit babcc20

Please sign in to comment.