Calls to window and document in src/core/ no longer break non-browser environments
This commit is contained in:
parent
dd5bd5d5e7
commit
6d396dbb9e
@ -388,7 +388,7 @@ const Utils = {
|
|||||||
var wordArray = CryptoJS.enc.Utf8.parse(str),
|
var wordArray = CryptoJS.enc.Utf8.parse(str),
|
||||||
byteArray = Utils.wordArrayToByteArray(wordArray);
|
byteArray = Utils.wordArrayToByteArray(wordArray);
|
||||||
|
|
||||||
if (str.length !== wordArray.sigBytes)
|
if (window && str.length !== wordArray.sigBytes)
|
||||||
window.app.options.attemptHighlight = false;
|
window.app.options.attemptHighlight = false;
|
||||||
return byteArray;
|
return byteArray;
|
||||||
},
|
},
|
||||||
@ -440,7 +440,7 @@ const Utils = {
|
|||||||
var wordArray = new CryptoJS.lib.WordArray.init(words, byteArray.length),
|
var wordArray = new CryptoJS.lib.WordArray.init(words, byteArray.length),
|
||||||
str = CryptoJS.enc.Utf8.stringify(wordArray);
|
str = CryptoJS.enc.Utf8.stringify(wordArray);
|
||||||
|
|
||||||
if (str.length !== wordArray.sigBytes)
|
if (window && str.length !== wordArray.sigBytes)
|
||||||
window.app.options.attemptHighlight = false;
|
window.app.options.attemptHighlight = false;
|
||||||
return str;
|
return str;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -58,6 +58,10 @@ const URL_ = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runParse: function(input, args) {
|
runParse: function(input, args) {
|
||||||
|
if (!document) {
|
||||||
|
throw "This operation only works in a browser.";
|
||||||
|
}
|
||||||
|
|
||||||
var a = document.createElement("a");
|
var a = document.createElement("a");
|
||||||
|
|
||||||
// Overwrite base href which will be the current CyberChef URL to reduce confusion.
|
// Overwrite base href which will be the current CyberChef URL to reduce confusion.
|
||||||
|
|||||||
@ -17,7 +17,7 @@ const UUID = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runGenerateV4: function(input, args) {
|
runGenerateV4: function(input, args) {
|
||||||
if (typeof(window.crypto) !== "undefined" && typeof(window.crypto.getRandomValues) !== "undefined") {
|
if (window && typeof(window.crypto) !== "undefined" && typeof(window.crypto.getRandomValues) !== "undefined") {
|
||||||
var buf = new Uint32Array(4),
|
var buf = new Uint32Array(4),
|
||||||
i = 0;
|
i = 0;
|
||||||
window.crypto.getRandomValues(buf);
|
window.crypto.getRandomValues(buf);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user