Fix HMAC empty hash function validation
This commit is contained in:
parent
d735496641
commit
d98dfcd6f8
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
import Utils from "../Utils.mjs";
|
import Utils from "../Utils.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import CryptoApi from "crypto-api/src/crypto-api.mjs";
|
import CryptoApi from "crypto-api/src/crypto-api.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,6 +68,10 @@ class HMAC extends Operation {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
|
if (!args[1]) {
|
||||||
|
throw new OperationError("Hashing function must be selected.");
|
||||||
|
}
|
||||||
|
|
||||||
const key = Utils.convertToByteString(args[0].string || "", args[0].option),
|
const key = Utils.convertToByteString(args[0].string || "", args[0].option),
|
||||||
hashFunc = args[1].toLowerCase(),
|
hashFunc = args[1].toLowerCase(),
|
||||||
msg = Utils.arrayBufferToStr(input, false),
|
msg = Utils.arrayBufferToStr(input, false),
|
||||||
|
|||||||
@ -661,6 +661,22 @@ WWFkYSBZYWRh\r
|
|||||||
assert.strictEqual(chef.HMAC("On Cloud Nine", {key: "idea"}).toString(), "e15c268b4ee755c9e52db094ed50add7");
|
assert.strictEqual(chef.HMAC("On Cloud Nine", {key: "idea"}).toString(), "e15c268b4ee755c9e52db094ed50add7");
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
it("HMAC rejects an empty hashing function", () => {
|
||||||
|
assert.throws(
|
||||||
|
() => chef.HMAC("hi", {
|
||||||
|
key: {
|
||||||
|
option: "UTF8",
|
||||||
|
string: "",
|
||||||
|
},
|
||||||
|
hashingFunction: "",
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
type: "OperationError",
|
||||||
|
message: "Hashing function must be selected.",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
|
||||||
it("JPathExpression", () => {
|
it("JPathExpression", () => {
|
||||||
assert.strictEqual(chef.JPathExpression("{\"key\" : \"value\"}", {query: "$.key"}).toString(), "\"value\"");
|
assert.strictEqual(chef.JPathExpression("{\"key\" : \"value\"}", {query: "$.key"}).toString(), "\"value\"");
|
||||||
}),
|
}),
|
||||||
@ -1178,4 +1194,3 @@ ExifImageHeight: 57`);
|
|||||||
|
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user