Make Argon2 WebAssembly module unload after use (#5072)
This commit is contained in:
parent
3185c0a61b
commit
f5c329030d
|
@ -69,6 +69,7 @@ export class WebCryptoFunctionService implements CryptoFunctionService {
|
|||
hashLen: 32,
|
||||
type: argon2.ArgonType.Argon2id,
|
||||
});
|
||||
argon2.unloadRuntime();
|
||||
return result.hash;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
diff --git a/node_modules/argon2-browser/lib/argon2.js b/node_modules/argon2-browser/lib/argon2.js
|
||||
index ffa77a5..b498e2d 100644
|
||||
index ffa77a5..98b2f13 100644
|
||||
--- a/node_modules/argon2-browser/lib/argon2.js
|
||||
+++ b/node_modules/argon2-browser/lib/argon2.js
|
||||
@@ -78,16 +78,27 @@
|
||||
|
@ -36,10 +36,16 @@ index ffa77a5..b498e2d 100644
|
|||
return fetch(wasmPath)
|
||||
.then((response) => response.arrayBuffer())
|
||||
.then((ab) => new Uint8Array(ab));
|
||||
@@ -354,6 +365,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,7 +362,28 @@
|
||||
loadModule._module.unloadRuntime();
|
||||
delete loadModule._promise;
|
||||
delete loadModule._module;
|
||||
+ if (typeof require !== 'undefined') {
|
||||
+ delete require.cache[require.resolve('../dist/argon2.js')]
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // ref: https://stackoverflow.com/a/47880734/1090359
|
||||
+ // ref: https://github.com/GoogleChromeLabs/wasm-feature-detect/blob/main/src/detectors/simd/module.wat (translated with wat2wasm)
|
||||
+ function checkIfSIMDSupported() {
|
||||
|
@ -54,10 +60,8 @@ index ffa77a5..b498e2d 100644
|
|||
+ }
|
||||
+ } catch {
|
||||
+ return false;
|
||||
+ }
|
||||
}
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
return {
|
||||
ArgonType,
|
||||
hash: argon2Hash,
|
||||
|
|
Loading…
Reference in New Issue