Skip to content

Commit

Permalink
Make ARGON2_WASM_MEMORY_THRESHOLD_RELOAD a 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 4bc84bc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 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
9 changes: 6 additions & 3 deletions src/type/s2k/argon2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

0 comments on commit 4bc84bc

Please sign in to comment.