mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Lint corrections
Lint corrections
This commit is contained in:
parent
16577751eb
commit
747eb1c192
3 changed files with 40 additions and 54 deletions
|
@ -28,33 +28,27 @@ export function toBase94(data, strictLength=true) {
|
||||||
|
|
||||||
if (data instanceof ArrayBuffer) {
|
if (data instanceof ArrayBuffer) {
|
||||||
data = new Uint8Array(data);
|
data = new Uint8Array(data);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new OperationError(`Invalid - Input not instanceof ArrayBuffer.`);
|
throw new OperationError(`Invalid - Input not instanceof ArrayBuffer.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let dataModLen = data.length % 4;
|
const dataModLen = data.length % 4;
|
||||||
|
|
||||||
if (dataModLen > 0 && strictLength)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
if (dataModLen > 0 && strictLength) {
|
||||||
throw new OperationError(`Invalid - Input byte length must be a multiple of 4.`);
|
throw new OperationError(`Invalid - Input byte length must be a multiple of 4.`);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = "", i = 0, j = 0, acc = 0;
|
let output = "", i = 0, j = 0, acc = 0;
|
||||||
|
|
||||||
let dataPad = new Uint8Array(data.length + (dataModLen > 0 ? (4 - dataModLen) : 0));
|
const dataPad = new Uint8Array(data.length + (dataModLen > 0 ? (4 - dataModLen) : 0));
|
||||||
|
|
||||||
dataPad.set(data,0);
|
dataPad.set(data, 0);
|
||||||
|
|
||||||
while (i < dataPad.length) {
|
while (i < dataPad.length) {
|
||||||
|
|
||||||
acc = 0;
|
acc = 0;
|
||||||
|
|
||||||
for(j = 0; j < 4; j++)
|
for (j = 0; j < 4; j++) {
|
||||||
{
|
|
||||||
|
|
||||||
acc *= 256;
|
acc *= 256;
|
||||||
|
|
||||||
|
@ -62,8 +56,7 @@ export function toBase94(data, strictLength=true) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(j = 0; j < 5; j++)
|
for (j = 0; j < 5; j++) {
|
||||||
{
|
|
||||||
|
|
||||||
output += String.fromCharCode((acc % 94)+32);
|
output += String.fromCharCode((acc % 94)+32);
|
||||||
|
|
||||||
|
@ -105,8 +98,7 @@ export function fromBase94(data, strictLength=true, removeInvalidChars=false) {
|
||||||
|
|
||||||
data = Utils.strToByteArray(data);
|
data = Utils.strToByteArray(data);
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
|
|
||||||
throw new OperationError(`Invalid - typeof base94 input is not a string.`);
|
throw new OperationError(`Invalid - typeof base94 input is not a string.`);
|
||||||
|
|
||||||
|
@ -114,30 +106,25 @@ export function fromBase94(data, strictLength=true, removeInvalidChars=false) {
|
||||||
|
|
||||||
const re = new RegExp("[^\x20-\x7e]", "g");
|
const re = new RegExp("[^\x20-\x7e]", "g");
|
||||||
|
|
||||||
if(re.test(data))
|
if (re.test(data)) {
|
||||||
{
|
|
||||||
if (removeInvalidChars) {
|
if (removeInvalidChars) {
|
||||||
data = data.replace(re, "");
|
data = data.replace(re, "");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new OperationError(`Invalid content in Base94 string.`);
|
throw new OperationError(`Invalid content in Base94 string.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let stringModLen = data.length % 5;
|
let stringModLen = data.length % 5;
|
||||||
|
|
||||||
if (stringModLen > 0)
|
if (stringModLen > 0) {
|
||||||
{
|
|
||||||
|
|
||||||
if(strictLength)
|
if (strictLength) {
|
||||||
{
|
|
||||||
throw new OperationError(`Invalid - Input string length must be a multiple of 5.`);
|
throw new OperationError(`Invalid - Input string length must be a multiple of 5.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
stringModLen = 5 - stringModLen;
|
stringModLen = 5 - stringModLen;
|
||||||
|
|
||||||
while(stringModLen > 0)
|
while (stringModLen > 0) {
|
||||||
{
|
|
||||||
|
|
||||||
data.push(32);
|
data.push(32);
|
||||||
|
|
||||||
|
@ -147,21 +134,20 @@ export function fromBase94(data, strictLength=true, removeInvalidChars=false) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = [], i = 0, j = 0, acc = 0;
|
const output = [];
|
||||||
|
let i = 0, j = 0, acc = 0;
|
||||||
|
|
||||||
while (i < data.length) {
|
while (i < data.length) {
|
||||||
|
|
||||||
acc = 0;
|
acc = 0;
|
||||||
|
|
||||||
for (j = 0; j < 5; j++)
|
for (j = 0; j < 5; j++) {
|
||||||
{
|
|
||||||
|
|
||||||
acc = (acc * 94) + data[i + 4 - j] - 32;
|
acc = (acc * 94) + data[i + 4 - j] - 32;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < 4; j++)
|
for (j = 0; j < 4; j++) {
|
||||||
{
|
|
||||||
|
|
||||||
output.push(acc % 256);
|
output.push(acc % 256);
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ class FromBase94 extends Operation {
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
|
|
||||||
const [strictLength,removeInvalidChars] = args;
|
const [strictLength, removeInvalidChars] = args;
|
||||||
|
|
||||||
return fromBase94(input, strictLength, removeInvalidChars);
|
return fromBase94(input, strictLength, removeInvalidChars);
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ class ToBase94 extends Operation {
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const [strictLength] = args;
|
const [strictLength] = args;
|
||||||
return toBase94(input,strictLength);
|
return toBase94(input, strictLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue