Merge branch 'slurdge-master'

feature-extract-files
n1474335 2017-10-09 15:20:52 +00:00
commit 1d78578fc2
1 changed files with 26 additions and 10 deletions

View File

@ -16,6 +16,22 @@ import Checksum from "./Checksum.js";
*/
const Hash = {
/**
* Generic hash function.
*
* @param {string} name
* @param {string} input
* @returns {string}
*/
runHash: function(name, input) {
const hasher = CryptoApi.hasher(name);
hasher.state.message = input;
hasher.state.length += input.length;
hasher.process();
return hasher.finalize().stringify("hex");
},
/**
* MD2 operation.
*
@ -24,7 +40,7 @@ const Hash = {
* @returns {string}
*/
runMD2: function (input, args) {
return CryptoApi.hash("md2", input, {}).stringify("hex");
return Hash.runHash("md2", input);
},
@ -36,7 +52,7 @@ const Hash = {
* @returns {string}
*/
runMD4: function (input, args) {
return CryptoApi.hash("md4", input, {}).stringify("hex");
return Hash.runHash("md4", input);
},
@ -48,7 +64,7 @@ const Hash = {
* @returns {string}
*/
runMD5: function (input, args) {
return CryptoApi.hash("md5", input, {}).stringify("hex");
return Hash.runHash("md5", input);
},
@ -92,7 +108,7 @@ const Hash = {
* @returns {string}
*/
runSHA0: function (input, args) {
return CryptoApi.hash("sha0", input, {}).stringify("hex");
return Hash.runHash("sha0", input);
},
@ -104,7 +120,7 @@ const Hash = {
* @returns {string}
*/
runSHA1: function (input, args) {
return CryptoApi.hash("sha1", input, {}).stringify("hex");
return Hash.runHash("sha1", input);
},
@ -123,7 +139,7 @@ const Hash = {
*/
runSHA2: function (input, args) {
const size = args[0];
return CryptoApi.hash("sha" + size, input, {}).stringify("hex");
return Hash.runHash("sha" + size, input);
},
@ -259,7 +275,7 @@ const Hash = {
*/
runRIPEMD: function (input, args) {
const size = args[0];
return CryptoApi.hash("ripemd" + size, input, {}).stringify("hex");
return Hash.runHash("ripemd" + size, input);
},
@ -271,7 +287,7 @@ const Hash = {
* @returns {string}
*/
runHAS: function (input, args) {
return CryptoApi.hash("has160", input, {}).stringify("hex");
return Hash.runHash("has160", input);
},
@ -290,7 +306,7 @@ const Hash = {
*/
runWhirlpool: function (input, args) {
const variant = args[0].toLowerCase();
return CryptoApi.hash(variant, input, {}).stringify("hex");
return Hash.runHash(variant, input);
},
@ -315,7 +331,7 @@ const Hash = {
runSnefru: function (input, args) {
const rounds = args[0],
size = args[1];
return CryptoApi.hash(`snefru-${rounds}-${size}`, input, {}).stringify("hex");
return Hash.runHash(`snefru-${rounds}-${size}`, input);
},