aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-04-13 11:19:58 +0200
committerWojtek Kosior <koszko@koszko.org>2022-04-13 12:21:15 +0200
commitd9441412a6052e5fb057d01b745208070f8bdfd4 (patch)
tree61baa2e17cfe492ef478f9d899d2f0826927521c
parent4d866cf6f8c051098ff001562cbf8cb84980473a (diff)
downloadbrowser-extension-d9441412a6052e5fb057d01b745208070f8bdfd4.tar.gz
browser-extension-d9441412a6052e5fb057d01b745208070f8bdfd4.zip
remove node-specific code from sha256.jsv1.0
this will prevent the eval warning when uploading extension to AMO
-rw-r--r--common/sha256.js32
1 files changed, 1 insertions, 31 deletions
diff --git a/common/sha256.js b/common/sha256.js
index 5149f97..13c8c7c 100644
--- a/common/sha256.js
+++ b/common/sha256.js
@@ -36,10 +36,7 @@ if (root.JS_SHA256_NO_WINDOW) {
WINDOW = false;
}
var WEB_WORKER = !WINDOW && typeof self === 'object';
-var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
-if (NODE_JS) {
- root = global;
-} else if (WEB_WORKER) {
+if (WEB_WORKER) {
root = self;
}
var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module === 'object' && module.exports;
@@ -82,9 +79,6 @@ var createOutputMethod = function (outputType, is224) {
var createMethod = function (is224) {
var method = createOutputMethod('hex', is224);
- if (NODE_JS) {
- method = nodeWrap(method, is224);
- }
method.create = function () {
return new Sha256(is224);
};
@@ -98,30 +92,6 @@ var createMethod = function (is224) {
return method;
};
-var nodeWrap = function (method, is224) {
- var crypto = eval("require('crypto')");
- var Buffer = eval("require('buffer').Buffer");
- var algorithm = is224 ? 'sha224' : 'sha256';
- var nodeMethod = function (message) {
- if (typeof message === 'string') {
- return crypto.createHash(algorithm).update(message, 'utf8').digest('hex');
- } else {
- if (message === null || message === undefined) {
- throw new Error(ERROR);
- } else if (message.constructor === ArrayBuffer) {
- message = new Uint8Array(message);
- }
- }
- if (Array.isArray(message) || ArrayBuffer.isView(message) ||
- message.constructor === Buffer) {
- return crypto.createHash(algorithm).update(new Buffer(message)).digest('hex');
- } else {
- return method(message);
- }
- };
- return nodeMethod;
-};
-
var createHmacOutputMethod = function (outputType, is224) {
return function (key, message) {
return new HmacSha256(key, is224, true).update(message)[outputType]();