index : matrix-js-sdk

My fork of matrix-js-sdk

diff options
context:
space:
mode:
authorPeter Cai <[email protected]>2020-07-04 16:50:32 +0800
committerPeter Cai <[email protected]>2020-07-04 16:50:32 +0800
commit2e7ba392e9895b3a66acf824d7599db21756728a (patch)
treecc140bfe23a8e5d0b4f018f17ef62218c7a85895
parentba6680a3e180bd1b7fcabb531310c515b195463d (diff)
downloadmatrix-js-sdk-2e7ba392e9895b3a66acf824d7599db21756728a.tar.gz
crypto: aes: support NativeCrypto7.0.0-zion
* I don't trust crypto-browserify. Use native implementation if possible. * These functions are only for local storage anyway, so anything that makes sense should be fine as a replacement. At least better than crypto-browserify.
-rw-r--r--src/crypto/aes.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/crypto/aes.js b/src/crypto/aes.js
index 1556413f..b9bf836d 100644
--- a/src/crypto/aes.js
+++ b/src/crypto/aes.js
@@ -23,6 +23,12 @@ const subtleCrypto = (typeof window !== "undefined" && window.crypto) ?
// salt for HKDF, with 8 bytes of zeros
const zerosalt = new Uint8Array(8);
+var nativeCrypto = null;
+
+export function setNativeCrypto(crypto) {
+ nativeCrypto = crypto;
+}
+
/**
* encrypt a string in Node.js
*
@@ -242,10 +248,16 @@ async function deriveKeysBrowser(key, name) {
}
export function encryptAES(...args) {
+ if (nativeCrypto) {
+ return nativeCrypto.encryptNative(...args);
+ }
return subtleCrypto ? encryptBrowser(...args) : encryptNode(...args);
}
export function decryptAES(...args) {
+ if (nativeCrypto) {
+ return nativeCrypto.decryptNative(...args);
+ }
return subtleCrypto ? decryptBrowser(...args) : decryptNode(...args);
}