mirror of
https://github.com/gchq/CyberChef
synced 2025-01-01 07:18:47 +00:00
Added maxLength property for string arguments
This commit is contained in:
parent
157346b055
commit
320f79fe0d
4 changed files with 20 additions and 9 deletions
|
@ -27,6 +27,7 @@ class Ingredient {
|
||||||
this.toggleValues = [];
|
this.toggleValues = [];
|
||||||
this.target = null;
|
this.target = null;
|
||||||
this.defaultIndex = 0;
|
this.defaultIndex = 0;
|
||||||
|
this.maxLength = null;
|
||||||
this.min = null;
|
this.min = null;
|
||||||
this.max = null;
|
this.max = null;
|
||||||
this.step = 1;
|
this.step = 1;
|
||||||
|
@ -53,6 +54,7 @@ class Ingredient {
|
||||||
this.toggleValues = ingredientConfig.toggleValues;
|
this.toggleValues = ingredientConfig.toggleValues;
|
||||||
this.target = typeof ingredientConfig.target !== "undefined" ? ingredientConfig.target : null;
|
this.target = typeof ingredientConfig.target !== "undefined" ? ingredientConfig.target : null;
|
||||||
this.defaultIndex = typeof ingredientConfig.defaultIndex !== "undefined" ? ingredientConfig.defaultIndex : 0;
|
this.defaultIndex = typeof ingredientConfig.defaultIndex !== "undefined" ? ingredientConfig.defaultIndex : 0;
|
||||||
|
this.maxLength = ingredientConfig.maxLength || null;
|
||||||
this.min = ingredientConfig.min;
|
this.min = ingredientConfig.min;
|
||||||
this.max = ingredientConfig.max;
|
this.max = ingredientConfig.max;
|
||||||
this.step = ingredientConfig.step;
|
this.step = ingredientConfig.step;
|
||||||
|
|
|
@ -184,6 +184,7 @@ class Operation {
|
||||||
if (ing.disabled) conf.disabled = ing.disabled;
|
if (ing.disabled) conf.disabled = ing.disabled;
|
||||||
if (ing.target) conf.target = ing.target;
|
if (ing.target) conf.target = ing.target;
|
||||||
if (ing.defaultIndex) conf.defaultIndex = ing.defaultIndex;
|
if (ing.defaultIndex) conf.defaultIndex = ing.defaultIndex;
|
||||||
|
if (ing.maxLength) conf.maxLength = ing.maxLength;
|
||||||
if (typeof ing.min === "number") conf.min = ing.min;
|
if (typeof ing.min === "number") conf.min = ing.min;
|
||||||
if (typeof ing.max === "number") conf.max = ing.max;
|
if (typeof ing.max === "number") conf.max = ing.max;
|
||||||
if (ing.step) conf.step = ing.step;
|
if (ing.step) conf.step = ing.step;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
import OperationError from "../errors/OperationError.mjs";
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import Utils from "../Utils.mjs";
|
import Utils from "../Utils.mjs";
|
||||||
import {alphabetName, ALPHABET_OPTIONS} from "../lib/Base85.mjs";
|
import {ALPHABET_OPTIONS} from "../lib/Base85.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* From Base85 operation
|
* From Base85 operation
|
||||||
|
@ -40,8 +40,9 @@ class FromBase85 extends Operation {
|
||||||
{
|
{
|
||||||
name: "All-zero group char",
|
name: "All-zero group char",
|
||||||
type: "binaryShortString",
|
type: "binaryShortString",
|
||||||
value: "z"
|
value: "z",
|
||||||
},
|
maxLength: 1
|
||||||
|
}
|
||||||
];
|
];
|
||||||
this.checks = [
|
this.checks = [
|
||||||
{
|
{
|
||||||
|
@ -81,9 +82,8 @@ class FromBase85 extends Operation {
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const alphabet = Utils.expandAlphRange(args[0]).join(""),
|
const alphabet = Utils.expandAlphRange(args[0]).join(""),
|
||||||
encoding = alphabetName(alphabet),
|
|
||||||
removeNonAlphChars = args[1],
|
removeNonAlphChars = args[1],
|
||||||
allZeroGroupChar = args[2],
|
allZeroGroupChar = typeof args[2] === "string" ? args[2].slice(0, 1) : "",
|
||||||
result = [];
|
result = [];
|
||||||
|
|
||||||
if (alphabet.length !== 85 ||
|
if (alphabet.length !== 85 ||
|
||||||
|
@ -91,6 +91,10 @@ class FromBase85 extends Operation {
|
||||||
throw new OperationError("Alphabet must be of length 85");
|
throw new OperationError("Alphabet must be of length 85");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (allZeroGroupChar && alphabet.includes(allZeroGroupChar)) {
|
||||||
|
throw new OperationError("The all-zero group char cannot appear in the alphabet");
|
||||||
|
}
|
||||||
|
|
||||||
// Remove delimiters if present
|
// Remove delimiters if present
|
||||||
const matches = input.match(/^<~(.+?)~>$/);
|
const matches = input.match(/^<~(.+?)~>$/);
|
||||||
if (matches !== null) input = matches[1];
|
if (matches !== null) input = matches[1];
|
||||||
|
@ -109,7 +113,7 @@ class FromBase85 extends Operation {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
let block, blockBytes;
|
let block, blockBytes;
|
||||||
while (i < input.length) {
|
while (i < input.length) {
|
||||||
if (encoding === "Standard" && input[i] === allZeroGroupChar) {
|
if (input[i] === allZeroGroupChar) {
|
||||||
result.push(0, 0, 0, 0);
|
result.push(0, 0, 0, 0);
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -30,6 +30,7 @@ class HTMLIngredient {
|
||||||
this.rows = config.rows || false;
|
this.rows = config.rows || false;
|
||||||
this.target = config.target;
|
this.target = config.target;
|
||||||
this.defaultIndex = config.defaultIndex || 0;
|
this.defaultIndex = config.defaultIndex || 0;
|
||||||
|
this.maxLength = config.maxLength || null;
|
||||||
this.toggleValues = config.toggleValues;
|
this.toggleValues = config.toggleValues;
|
||||||
this.ingId = this.app.nextIngId();
|
this.ingId = this.app.nextIngId();
|
||||||
this.id = "ing-" + this.ingId;
|
this.id = "ing-" + this.ingId;
|
||||||
|
@ -63,7 +64,8 @@ class HTMLIngredient {
|
||||||
tabindex="${this.tabIndex}"
|
tabindex="${this.tabIndex}"
|
||||||
arg-name="${this.name}"
|
arg-name="${this.name}"
|
||||||
value="${this.value}"
|
value="${this.value}"
|
||||||
${this.disabled ? "disabled" : ""}>
|
${this.disabled ? "disabled" : ""}
|
||||||
|
${this.maxLength ? `maxlength="${this.maxLength}"` : ""}>
|
||||||
</div>`;
|
</div>`;
|
||||||
break;
|
break;
|
||||||
case "shortString":
|
case "shortString":
|
||||||
|
@ -78,7 +80,8 @@ class HTMLIngredient {
|
||||||
tabindex="${this.tabIndex}"
|
tabindex="${this.tabIndex}"
|
||||||
arg-name="${this.name}"
|
arg-name="${this.name}"
|
||||||
value="${this.value}"
|
value="${this.value}"
|
||||||
${this.disabled ? "disabled" : ""}>
|
${this.disabled ? "disabled" : ""}
|
||||||
|
${this.maxLength ? `maxlength="${this.maxLength}"` : ""}>
|
||||||
</div>`;
|
</div>`;
|
||||||
break;
|
break;
|
||||||
case "toggleString":
|
case "toggleString":
|
||||||
|
@ -93,7 +96,8 @@ class HTMLIngredient {
|
||||||
tabindex="${this.tabIndex}"
|
tabindex="${this.tabIndex}"
|
||||||
arg-name="${this.name}"
|
arg-name="${this.name}"
|
||||||
value="${this.value}"
|
value="${this.value}"
|
||||||
${this.disabled ? "disabled" : ""}>
|
${this.disabled ? "disabled" : ""}
|
||||||
|
${this.maxLength ? `maxlength="${this.maxLength}"` : ""}>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-group-append">
|
<div class="input-group-append">
|
||||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">${this.toggleValues[0]}</button>
|
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">${this.toggleValues[0]}</button>
|
||||||
|
|
Loading…
Reference in a new issue