mirror of
https://github.com/gchq/CyberChef
synced 2025-01-15 14:03:54 +00:00
Introduced use of conditional chaining operator
This commit is contained in:
parent
570206af77
commit
b92501ee35
14 changed files with 493 additions and 495 deletions
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"parser": "@babel/eslint-parser",
|
"parser": "@babel/eslint-parser",
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 9,
|
"ecmaVersion": 2022,
|
||||||
"ecmaFeatures": {
|
"ecmaFeatures": {
|
||||||
"impliedStrict": true
|
"impliedStrict": true
|
||||||
},
|
},
|
||||||
|
|
|
@ -230,14 +230,12 @@ class Recipe {
|
||||||
this.lastRunOp = op;
|
this.lastRunOp = op;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Return expected errors as output
|
// Return expected errors as output
|
||||||
if (err instanceof OperationError ||
|
if (err instanceof OperationError || err?.type === "OperationError") {
|
||||||
(err.type && err.type === "OperationError")) {
|
|
||||||
// Cannot rely on `err instanceof OperationError` here as extending
|
// Cannot rely on `err instanceof OperationError` here as extending
|
||||||
// native types is not fully supported yet.
|
// native types is not fully supported yet.
|
||||||
dish.set(err.message, "string");
|
dish.set(err.message, "string");
|
||||||
return i;
|
return i;
|
||||||
} else if (err instanceof DishError ||
|
} else if (err instanceof DishError || err?.type === "DishError") {
|
||||||
(err.type && err.type === "DishError")) {
|
|
||||||
dish.set(err.message, "string");
|
dish.set(err.message, "string");
|
||||||
return i;
|
return i;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -65,7 +65,7 @@ class DetectFileType extends Operation {
|
||||||
Extension: ${type.extension}
|
Extension: ${type.extension}
|
||||||
MIME type: ${type.mime}\n`;
|
MIME type: ${type.mime}\n`;
|
||||||
|
|
||||||
if (type.description && type.description.length) {
|
if (type?.description?.length) {
|
||||||
output += `Description: ${type.description}\n`;
|
output += `Description: ${type.description}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ class ScanForEmbeddedFiles extends Operation {
|
||||||
Extension: ${type.fileDetails.extension}
|
Extension: ${type.fileDetails.extension}
|
||||||
MIME type: ${type.fileDetails.mime}\n`;
|
MIME type: ${type.fileDetails.mime}\n`;
|
||||||
|
|
||||||
if (type.fileDetails.description && type.fileDetails.description.length) {
|
if (type?.fileDetails?.description?.length) {
|
||||||
output += ` Description: ${type.fileDetails.description}\n`;
|
output += ` Description: ${type.fileDetails.description}\n`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
4
src/core/vendor/gost/gostCipher.mjs
vendored
4
src/core/vendor/gost/gostCipher.mjs
vendored
|
@ -198,7 +198,7 @@ function randomSeed(e) {
|
||||||
function buffer(d) {
|
function buffer(d) {
|
||||||
if (d instanceof CryptoOperationData)
|
if (d instanceof CryptoOperationData)
|
||||||
return d;
|
return d;
|
||||||
else if (d && d.buffer && d.buffer instanceof CryptoOperationData)
|
else if (d && d?.buffer instanceof CryptoOperationData)
|
||||||
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
|
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
|
||||||
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
|
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
|
||||||
else
|
else
|
||||||
|
@ -2076,7 +2076,7 @@ function GostCipher(algorithm) // <editor-fold defaultstate="collapsed">
|
||||||
((algorithm.keyWrapping || 'NO') !== 'NO' ? algorithm.keyWrapping : '') + 'KW' :
|
((algorithm.keyWrapping || 'NO') !== 'NO' ? algorithm.keyWrapping : '') + 'KW' :
|
||||||
(algorithm.block || 'ECB') + ((algorithm.block === 'CFB' || algorithm.block === 'OFB' ||
|
(algorithm.block || 'ECB') + ((algorithm.block === 'CFB' || algorithm.block === 'OFB' ||
|
||||||
(algorithm.block === 'CTR' && algorithm.version === 2015)) &&
|
(algorithm.block === 'CTR' && algorithm.version === 2015)) &&
|
||||||
algorithm.shiftBits && algorithm.shiftBits !== this.blockLength ? '-' + algorithm.shiftBits : '') +
|
algorithm?.shiftBits !== this.blockLength ? '-' + algorithm.shiftBits : '') +
|
||||||
(algorithm.padding ? '-' + (algorithm.padding || (algorithm.block === 'CTR' ||
|
(algorithm.padding ? '-' + (algorithm.padding || (algorithm.block === 'CTR' ||
|
||||||
algorithm.block === 'CFB' || algorithm.block === 'OFB' ? 'NO' : 'ZERO')) + 'PADDING' : '') +
|
algorithm.block === 'CFB' || algorithm.block === 'OFB' ? 'NO' : 'ZERO')) + 'PADDING' : '') +
|
||||||
((algorithm.keyMeshing || 'NO') !== 'NO' ? '-CPKEYMESHING' : '')) +
|
((algorithm.keyMeshing || 'NO') !== 'NO' ? '-CPKEYMESHING' : '')) +
|
||||||
|
|
2
src/core/vendor/gost/gostCoding.mjs
vendored
2
src/core/vendor/gost/gostCoding.mjs
vendored
|
@ -48,7 +48,7 @@ var Date = Date;
|
||||||
function buffer(d) {
|
function buffer(d) {
|
||||||
if (d instanceof CryptoOperationData)
|
if (d instanceof CryptoOperationData)
|
||||||
return d;
|
return d;
|
||||||
else if (d && d.buffer && d.buffer instanceof CryptoOperationData)
|
else if (d && d?.buffer instanceof CryptoOperationData)
|
||||||
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
|
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
|
||||||
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
|
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
|
||||||
else
|
else
|
||||||
|
|
10
src/core/vendor/gost/gostCrypto.mjs
vendored
10
src/core/vendor/gost/gostCrypto.mjs
vendored
|
@ -611,7 +611,7 @@ if (!Promise) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
value = mswrap(value);
|
value = mswrap(value);
|
||||||
if (value && value.then && value.then.call) {
|
if (value && value?.then?.call) {
|
||||||
value.then(resolve, reject);
|
value.then(resolve, reject);
|
||||||
} else {
|
} else {
|
||||||
resolve(value);
|
resolve(value);
|
||||||
|
@ -627,7 +627,7 @@ if (!Promise) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
reason = mswrap(reason);
|
reason = mswrap(reason);
|
||||||
if (reason && reason.then && reason.then.call) {
|
if (reason && reason?.then?.call) {
|
||||||
reason.then(resolve, reject);
|
reason.then(resolve, reject);
|
||||||
} else {
|
} else {
|
||||||
reject(reason);
|
reject(reason);
|
||||||
|
@ -698,7 +698,7 @@ if (!Promise) {
|
||||||
|
|
||||||
for (var i = 0, n = promises.length; i < n; i++) {
|
for (var i = 0, n = promises.length; i < n; i++) {
|
||||||
var data = promises[i];
|
var data = promises[i];
|
||||||
if (data.then && data.then.call)
|
if (data?.then?.call)
|
||||||
data.then(asyncResolve(i), asyncReject);
|
data.then(asyncResolve(i), asyncReject);
|
||||||
else
|
else
|
||||||
result[i] = data;
|
result[i] = data;
|
||||||
|
@ -1492,7 +1492,7 @@ SubtleCrypto.prototype.exportKey = function (format, key) // <editor-fold defaul
|
||||||
var raw = extractKey(null, null, key);
|
var raw = extractKey(null, null, key);
|
||||||
if (format === 'raw')
|
if (format === 'raw')
|
||||||
return raw;
|
return raw;
|
||||||
else if (format === 'pkcs8' && key.algorithm && key.algorithm.id) {
|
else if (format === 'pkcs8' && key?.algorithm?.id) {
|
||||||
if (key.algorithm.procreator === 'VN') {
|
if (key.algorithm.procreator === 'VN') {
|
||||||
// Add masks for ViPNet
|
// Add masks for ViPNet
|
||||||
var algorithm = key.algorithm, mask;
|
var algorithm = key.algorithm, mask;
|
||||||
|
@ -1514,7 +1514,7 @@ SubtleCrypto.prototype.exportKey = function (format, key) // <editor-fold defaul
|
||||||
});
|
});
|
||||||
} else
|
} else
|
||||||
return gostCrypto.asn1.GostPrivateKeyInfo.encode(key);
|
return gostCrypto.asn1.GostPrivateKeyInfo.encode(key);
|
||||||
} else if (format === 'spki' && key.algorithm && key.algorithm.id)
|
} else if (format === 'spki' && key?.algorithm?.id)
|
||||||
return gostCrypto.asn1.GostSubjectPublicKeyInfo.encode(key);
|
return gostCrypto.asn1.GostSubjectPublicKeyInfo.encode(key);
|
||||||
else
|
else
|
||||||
throw new NotSupportedError('Key format not supported');
|
throw new NotSupportedError('Key format not supported');
|
||||||
|
|
2
src/core/vendor/gost/gostDigest.mjs
vendored
2
src/core/vendor/gost/gostDigest.mjs
vendored
|
@ -113,7 +113,7 @@ function getSeed(length) {
|
||||||
function buffer(d) {
|
function buffer(d) {
|
||||||
if (d instanceof ArrayBuffer)
|
if (d instanceof ArrayBuffer)
|
||||||
return d;
|
return d;
|
||||||
else if (d && d.buffer && d.buffer instanceof ArrayBuffer)
|
else if (d && d?.buffer instanceof ArrayBuffer)
|
||||||
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
|
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
|
||||||
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
|
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
|
||||||
else
|
else
|
||||||
|
|
2
src/core/vendor/gost/gostSign.mjs
vendored
2
src/core/vendor/gost/gostSign.mjs
vendored
|
@ -1445,7 +1445,7 @@ function hash(d) {
|
||||||
function buffer(d) {
|
function buffer(d) {
|
||||||
if (d instanceof CryptoOperationData)
|
if (d instanceof CryptoOperationData)
|
||||||
return d;
|
return d;
|
||||||
else if (d && d.buffer && d.buffer instanceof CryptoOperationData)
|
else if (d && d?.buffer instanceof CryptoOperationData)
|
||||||
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
|
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
|
||||||
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
|
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
|
||||||
else
|
else
|
||||||
|
|
|
@ -342,7 +342,7 @@ class App {
|
||||||
let favourites;
|
let favourites;
|
||||||
|
|
||||||
if (this.isLocalStorageAvailable()) {
|
if (this.isLocalStorageAvailable()) {
|
||||||
favourites = localStorage.favourites && localStorage.favourites.length > 2 ?
|
favourites = localStorage?.favourites?.length > 2 ?
|
||||||
JSON.parse(localStorage.favourites) :
|
JSON.parse(localStorage.favourites) :
|
||||||
this.dfavourites;
|
this.dfavourites;
|
||||||
favourites = this.validFavourites(favourites);
|
favourites = this.validFavourites(favourites);
|
||||||
|
|
|
@ -159,7 +159,7 @@ class StatusBarPanel {
|
||||||
* @param {boolean} selectionSet
|
* @param {boolean} selectionSet
|
||||||
*/
|
*/
|
||||||
updateSelection(state, selectionSet) {
|
updateSelection(state, selectionSet) {
|
||||||
const selLen = state.selection && state.selection.main ?
|
const selLen = state?.selection?.main ?
|
||||||
state.selection.main.to - state.selection.main.from :
|
state.selection.main.to - state.selection.main.from :
|
||||||
0;
|
0;
|
||||||
|
|
||||||
|
|
|
@ -807,7 +807,7 @@ class InputWaiter {
|
||||||
// Dropped text is handled by the editor itself
|
// Dropped text is handled by the editor itself
|
||||||
if (e.dataTransfer.getData("Text")) return;
|
if (e.dataTransfer.getData("Text")) return;
|
||||||
|
|
||||||
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
if (e?.dataTransfer?.files?.length > 0) {
|
||||||
this.loadUIFiles(e.dataTransfer.files);
|
this.loadUIFiles(e.dataTransfer.files);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ class OutputWaiter {
|
||||||
getEOLSeq() {
|
getEOLSeq() {
|
||||||
const currentTabNum = this.manager.tabs.getActiveTab("output");
|
const currentTabNum = this.manager.tabs.getActiveTab("output");
|
||||||
if (currentTabNum < 0) {
|
if (currentTabNum < 0) {
|
||||||
return this.outputEditorConf.state.lineBreak;
|
return this.outputEditorConf.state?.lineBreak || "\n";
|
||||||
}
|
}
|
||||||
return this.outputs[currentTabNum].eolSequence;
|
return this.outputs[currentTabNum].eolSequence;
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ class RecipeWaiter {
|
||||||
// Reinitialise the popover on the original element in the ops list because for some reason it
|
// Reinitialise the popover on the original element in the ops list because for some reason it
|
||||||
// gets destroyed and recreated. If the clone isn't in the ops list, we use the original item instead.
|
// gets destroyed and recreated. If the clone isn't in the ops list, we use the original item instead.
|
||||||
let enableOpsElement;
|
let enableOpsElement;
|
||||||
if (evt.clone.parentNode && evt.clone.parentNode.classList.contains("op-list")) {
|
if (evt.clone?.parentNode?.classList?.contains("op-list")) {
|
||||||
enableOpsElement = evt.clone;
|
enableOpsElement = evt.clone;
|
||||||
} else {
|
} else {
|
||||||
enableOpsElement = evt.item;
|
enableOpsElement = evt.item;
|
||||||
|
@ -163,13 +163,13 @@ class RecipeWaiter {
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (e.target.className && e.target.className.indexOf("category-title") > -1) {
|
if (e.target?.className?.indexOf("category-title") > -1) {
|
||||||
// Hovering over the a
|
// Hovering over the a
|
||||||
e.target.classList.add("favourites-hover");
|
e.target.classList.add("favourites-hover");
|
||||||
} else if (e.target.parentNode.className && e.target.parentNode.className.indexOf("category-title") > -1) {
|
} else if (e.target?.parentNode?.className?.indexOf("category-title") > -1) {
|
||||||
// Hovering over the Edit button
|
// Hovering over the Edit button
|
||||||
e.target.parentNode.classList.add("favourites-hover");
|
e.target.parentNode.classList.add("favourites-hover");
|
||||||
} else if (e.target.parentNode.parentNode.className && e.target.parentNode.parentNode.className.indexOf("category-title") > -1) {
|
} else if (e.target?.parentNode?.parentNode?.className?.indexOf("category-title") > -1) {
|
||||||
// Hovering over the image on the Edit button
|
// Hovering over the image on the Edit button
|
||||||
e.target.parentNode.parentNode.classList.add("favourites-hover");
|
e.target.parentNode.parentNode.classList.add("favourites-hover");
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ class RecipeWaiter {
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
*/
|
*/
|
||||||
ingChange(e) {
|
ingChange(e) {
|
||||||
if (e && e.target && e.target.classList.contains("no-state-change")) return;
|
if (e && e?.target?.classList?.contains("no-state-change")) return;
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue