Initial Commit – Working hash functionality

This commit is contained in:
h345983745 2019-03-26 19:09:57 +00:00
parent 4fb4764d3f
commit 7d16265c4e
7 changed files with 189 additions and 0 deletions

View file

@ -0,0 +1,48 @@
/**
* @author h [h]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation";
import blakejs from "blakejs";
/**
* BLAKE2b operation
*/
class BLAKE2b extends Operation {
/**
* BLAKE2b constructor
*/
constructor() {
super();
this.name = "BLAKE2b";
this.module = "Hashing";
this.description = "Performs BLAKE2b hashing on the input. Returns the output HEX encoded.";
this.infoURL = "https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Size",
"type": "option",
"value": ["512", "384", "256", "160", "128"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string} The input having been hashed with BLAKE2b, HEX encoded.
*/
run(input, args) {
const [outSize] = args;
return blakejs.blake2bHex(input, null, outSize / 8);
}
}
export default BLAKE2b;

View file

@ -0,0 +1,48 @@
/**
* @author h [h]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation";
import blakejs from "blakejs";
/**
* BLAKE2s Operation
*/
class BLAKE2s extends Operation {
/**
* BLAKE2s constructor
*/
constructor() {
super();
this.name = "BLAKE2s";
this.module = "Hashing";
this.description = "Performs BLAKE2s hashing on the input. Returns the output HEX encoded.";
this.infoURL = "https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Size",
"type": "option",
"value": ["256", "160", "128"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string} The input having been hashed with BLAKE2s, HEX encoded.
*/
run(input, args) {
const [outSize] = args;
return blakejs.blake2sHex(input, null, outSize / 8);
}
}
export default BLAKE2s;