Fix config.use_native
This commit is contained in:
parent
53d6f20b72
commit
d5d4c97228
|
@ -137,9 +137,9 @@ function concat(...arrays) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function CTR(plaintext, key, iv) {
|
function CTR(plaintext, key, iv) {
|
||||||
if (webCrypto && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
if (util.getWebCryptoAll() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
||||||
return webCtr(plaintext, key, iv);
|
return webCtr(plaintext, key, iv);
|
||||||
} else if (nodeCrypto) { // Node crypto library
|
} else if (util.getNodeCrypto()) { // Node crypto library
|
||||||
return nodeCtr(plaintext, key, iv);
|
return nodeCtr(plaintext, key, iv);
|
||||||
} // asm.js fallback
|
} // asm.js fallback
|
||||||
return Promise.resolve(AES_CTR.encrypt(plaintext, key, iv));
|
return Promise.resolve(AES_CTR.encrypt(plaintext, key, iv));
|
||||||
|
|
|
@ -49,9 +49,9 @@ function encrypt(cipher, plaintext, key, iv) {
|
||||||
return Promise.reject(new Error('GCM mode supports only AES cipher'));
|
return Promise.reject(new Error('GCM mode supports only AES cipher'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (webCrypto && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
||||||
return webEncrypt(plaintext, key, iv);
|
return webEncrypt(plaintext, key, iv);
|
||||||
} else if (nodeCrypto) { // Node crypto library
|
} else if (util.getNodeCrypto()) { // Node crypto library
|
||||||
return nodeEncrypt(plaintext, key, iv);
|
return nodeEncrypt(plaintext, key, iv);
|
||||||
} // asm.js fallback
|
} // asm.js fallback
|
||||||
return Promise.resolve(AES_GCM.encrypt(plaintext, key, iv));
|
return Promise.resolve(AES_GCM.encrypt(plaintext, key, iv));
|
||||||
|
@ -70,9 +70,9 @@ function decrypt(cipher, ciphertext, key, iv) {
|
||||||
return Promise.reject(new Error('GCM mode supports only AES cipher'));
|
return Promise.reject(new Error('GCM mode supports only AES cipher'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (webCrypto && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
||||||
return webDecrypt(ciphertext, key, iv);
|
return webDecrypt(ciphertext, key, iv);
|
||||||
} else if (nodeCrypto) { // Node crypto library
|
} else if (util.getNodeCrypto()) { // Node crypto library
|
||||||
return nodeDecrypt(ciphertext, key, iv);
|
return nodeDecrypt(ciphertext, key, iv);
|
||||||
} // asm.js fallback
|
} // asm.js fallback
|
||||||
return Promise.resolve(AES_GCM.decrypt(ciphertext, key, iv));
|
return Promise.resolve(AES_GCM.decrypt(ciphertext, key, iv));
|
||||||
|
|
|
@ -182,14 +182,14 @@ Curve.prototype.keyFromPublic = function (pub) {
|
||||||
|
|
||||||
Curve.prototype.genKeyPair = async function () {
|
Curve.prototype.genKeyPair = async function () {
|
||||||
let keyPair;
|
let keyPair;
|
||||||
if (webCrypto && this.web) {
|
if (this.web && util.getWebCrypto()) {
|
||||||
// If browser doesn't support a curve, we'll catch it
|
// If browser doesn't support a curve, we'll catch it
|
||||||
try {
|
try {
|
||||||
keyPair = await webGenKeyPair(this.name);
|
keyPair = await webGenKeyPair(this.name);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
util.print_debug("Browser did not support signing: " + err.message);
|
util.print_debug("Browser did not support signing: " + err.message);
|
||||||
}
|
}
|
||||||
} else if (nodeCrypto && this.node) {
|
} else if (this.node && util.getNodeCrypto()) {
|
||||||
keyPair = await nodeGenKeyPair(this.name);
|
keyPair = await nodeGenKeyPair(this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ function KeyPair(curve, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyPair.prototype.sign = async function (message, hash_algo) {
|
KeyPair.prototype.sign = async function (message, hash_algo) {
|
||||||
if (webCrypto && this.curve.web) {
|
if (this.curve.web && util.getWebCrypto()) {
|
||||||
// If browser doesn't support a curve, we'll catch it
|
// If browser doesn't support a curve, we'll catch it
|
||||||
try {
|
try {
|
||||||
// need to await to make sure browser succeeds
|
// need to await to make sure browser succeeds
|
||||||
|
@ -54,7 +54,7 @@ KeyPair.prototype.sign = async function (message, hash_algo) {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
util.print_debug("Browser did not support signing: " + err.message);
|
util.print_debug("Browser did not support signing: " + err.message);
|
||||||
}
|
}
|
||||||
} else if (nodeCrypto && this.curve.node) {
|
} else if (this.curve.node && util.getNodeCrypto()) {
|
||||||
return nodeSign(this.curve, hash_algo, message, this.keyPair);
|
return nodeSign(this.curve, hash_algo, message, this.keyPair);
|
||||||
}
|
}
|
||||||
const digest = (typeof hash_algo === 'undefined') ? message : hash.digest(hash_algo, message);
|
const digest = (typeof hash_algo === 'undefined') ? message : hash.digest(hash_algo, message);
|
||||||
|
@ -62,7 +62,7 @@ KeyPair.prototype.sign = async function (message, hash_algo) {
|
||||||
};
|
};
|
||||||
|
|
||||||
KeyPair.prototype.verify = async function (message, signature, hash_algo) {
|
KeyPair.prototype.verify = async function (message, signature, hash_algo) {
|
||||||
if (webCrypto && this.curve.web) {
|
if (this.curve.web && util.getWebCrypto()) {
|
||||||
// If browser doesn't support a curve, we'll catch it
|
// If browser doesn't support a curve, we'll catch it
|
||||||
try {
|
try {
|
||||||
// need to await to make sure browser succeeds
|
// need to await to make sure browser succeeds
|
||||||
|
@ -71,7 +71,7 @@ KeyPair.prototype.verify = async function (message, signature, hash_algo) {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
util.print_debug("Browser did not support signing: " + err.message);
|
util.print_debug("Browser did not support signing: " + err.message);
|
||||||
}
|
}
|
||||||
} else if (nodeCrypto && this.curve.node) {
|
} else if (this.curve.node && util.getNodeCrypto()) {
|
||||||
return nodeVerify(this.curve, hash_algo, signature, message, this.keyPair.getPublic());
|
return nodeVerify(this.curve, hash_algo, signature, message, this.keyPair.getPublic());
|
||||||
}
|
}
|
||||||
const digest = (typeof hash_algo === 'undefined') ? message : hash.digest(hash_algo, message);
|
const digest = (typeof hash_algo === 'undefined') ? message : hash.digest(hash_algo, message);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user