Improve parameter validation for a number of operations where exceptions otherwise caused. (#2586)
This commit is contained in:
parent
a0a369a7ef
commit
080357a4f5
@ -30,7 +30,11 @@ class BLAKE3 extends Operation {
|
||||
this.args = [
|
||||
{
|
||||
"name": "Size (bytes)",
|
||||
"type": "number"
|
||||
"type": "number",
|
||||
"value": 16,
|
||||
"min": 1,
|
||||
"max": 65535, // arbitrary limit to prevent resource exhaustion
|
||||
"integer": true,
|
||||
}, {
|
||||
"name": "Key",
|
||||
"type": "string",
|
||||
|
||||
@ -27,7 +27,10 @@ class BitShiftLeft extends Operation {
|
||||
{
|
||||
"name": "Amount",
|
||||
"type": "number",
|
||||
"value": 1
|
||||
"value": 1,
|
||||
"min": 0,
|
||||
"max": 7,
|
||||
"integer": true,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
@ -31,7 +31,8 @@ class PseudoRandomNumberGenerator extends Operation {
|
||||
{
|
||||
"name": "Number of bytes",
|
||||
"type": "number",
|
||||
"value": 32
|
||||
"value": 32,
|
||||
"min": 1
|
||||
},
|
||||
{
|
||||
"name": "Output as",
|
||||
|
||||
@ -28,7 +28,10 @@ class ToBase extends Operation {
|
||||
{
|
||||
"name": "Radix",
|
||||
"type": "number",
|
||||
"value": 36
|
||||
"value": 36,
|
||||
"min": 2,
|
||||
"max": 36,
|
||||
"integer": true,
|
||||
}
|
||||
];
|
||||
}
|
||||
@ -43,9 +46,6 @@ class ToBase extends Operation {
|
||||
throw new OperationError("Error: Input must be a number");
|
||||
}
|
||||
const radix = args[0];
|
||||
if (radix < 2 || radix > 36) {
|
||||
throw new OperationError("Error: Radix argument must be between 2 and 36");
|
||||
}
|
||||
return input.toString(radix);
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,10 @@ class ToBinary extends Operation {
|
||||
{
|
||||
"name": "Byte Length",
|
||||
"type": "number",
|
||||
"value": 8
|
||||
"value": 8,
|
||||
"min": 1,
|
||||
"max": 256, // arbitrary - significantly larger than word size for any known machine ("640k ought to be enough for anybody")
|
||||
"integer": true
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
@ -31,7 +31,10 @@ class XORBruteForce extends Operation {
|
||||
{
|
||||
"name": "Key length",
|
||||
"type": "number",
|
||||
"value": 1
|
||||
"value": 1,
|
||||
"min": 1,
|
||||
"max": 2,
|
||||
"integer": true
|
||||
},
|
||||
{
|
||||
"name": "Sample length",
|
||||
|
||||
@ -69,5 +69,43 @@ TestRegister.addTests([
|
||||
{ "op": "BLAKE3",
|
||||
"args": [16390, "ThiskeyisexactlythirtytwoBytesLo"] }
|
||||
]
|
||||
},
|
||||
// test vectors from https://github.com/BLAKE3-team/BLAKE3/blob/master/test_vectors/test_vectors.json
|
||||
{
|
||||
name: "BLAKE3: Std test vector - 0 bytes input, plain hash",
|
||||
input: "",
|
||||
expectedOutput: "af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262e00f03e7b69af26b7faaf09fcd333050338ddfe085b8cc869ca98b206c08243a26f5487789e8f660afe6c99ef9e0c52b92e7393024a80459cf91f476f9ffdbda7001c22e159b402631f277ca96f2defdf1078282314e763699a31c5363165421cce14d",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "BLAKE3",
|
||||
"args": [131, ""]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE3: Std test vector - 0 bytes input, keyed hash",
|
||||
input: "",
|
||||
expectedOutput: "92b2b75604ed3c761f9d6f62392c8a9227ad0ea3f09573e783f1498a4ed60d26b18171a2f22a4b94822c701f107153dba24918c4bae4d2945c20ece13387627d3b73cbf97b797d5e59948c7ef788f54372df45e45e4293c7dc18c1d41144a9758be58960856be1eabbe22c2653190de560ca3b2ac4aa692a9210694254c371e851bc8f",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "BLAKE3",
|
||||
"args": [131, "whats the Elvish word for friend"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE3: Std test vector - 7 bytes input, keyed hash",
|
||||
input: "0001020304050607",
|
||||
expectedOutput: "be2f5495c61cba1bb348a34948c004045e3bd4dae8f0fe82bf44d0da245a060048eb5e68ce6dea1eb0229e144f578b3aa7e9f4f85febd135df8525e6fe40c6f0340d13dd09b255ccd5112a94238f2be3c0b5b7ecde06580426a93e0708555a265305abf86d874e34b4995b788e37a823491f25127a502fe0704baa6bfdf04e76c13276",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Hex",
|
||||
args: [],
|
||||
},
|
||||
{
|
||||
"op": "BLAKE3",
|
||||
"args": [131, "whats the Elvish word for friend"]
|
||||
}
|
||||
]
|
||||
},
|
||||
]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user