From d9441412a6052e5fb057d01b745208070f8bdfd4 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 13 Apr 2022 11:19:58 +0200 Subject: remove node-specific code from sha256.js this will prevent the eval warning when uploading extension to AMO --- common/sha256.js | 32 +------------------------------- 1 file changed, 1 insertion(+), 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](); -- cgit v1.2.3