mirror of
https://github.com/gchq/CyberChef.git
synced 2024-09-30 07:21:29 +02:00
Throw OperationError instead of returning a String
This commit is contained in:
parent
1509b2b96c
commit
0ab96dd4ca
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rail Fence Cipher Decode operation
|
* Rail Fence Cipher Decode operation
|
||||||
@ -48,13 +49,13 @@ class RailFenceCipherDecode extends Operation {
|
|||||||
let cipher = input;
|
let cipher = input;
|
||||||
|
|
||||||
if (key < 2) {
|
if (key < 2) {
|
||||||
return "Key has to be bigger than 2";
|
throw new OperationError("Key has to be bigger than 2");
|
||||||
} else if (key > cipher.length) {
|
} else if (key > cipher.length) {
|
||||||
return "Key should be smaller than the cipher's length";
|
throw new OperationError("Key should be smaller than the cipher's length");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
return "Offset has to be a positive integer";
|
throw new OperationError("Offset has to be a positive integer");
|
||||||
}
|
}
|
||||||
|
|
||||||
const cycle = (key - 1) * 2;
|
const cycle = (key - 1) * 2;
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rail Fence Cipher Encode operation
|
* Rail Fence Cipher Encode operation
|
||||||
@ -47,13 +48,13 @@ class RailFenceCipherEncode extends Operation {
|
|||||||
|
|
||||||
const plaintext = input;
|
const plaintext = input;
|
||||||
if (key < 2) {
|
if (key < 2) {
|
||||||
return "Key has to be bigger than 2";
|
throw new OperationError("Key has to be bigger than 2");
|
||||||
} else if (key > plaintext.length) {
|
} else if (key > plaintext.length) {
|
||||||
return "Key should be smaller than the plain text's length";
|
throw new OperationError("Key should be smaller than the plain text's length");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
return "Offset has to be a positive integer";
|
throw new OperationError("Offset has to be a positive integer");
|
||||||
}
|
}
|
||||||
|
|
||||||
const cycle = (key - 1) * 2;
|
const cycle = (key - 1) * 2;
|
||||||
|
Loading…
Reference in New Issue
Block a user