sha224
Version:
A Javascript implementation of SHA-224 for Node.js.
95 lines (79 loc) • 2.96 kB
JavaScript
// 80
////////////////////////////////////////////////////////////////////////////////
/*
test.js
(Javascript code for testing SHA224-Node.js)
developed
by K. (https://github.com/wlzla000)
on January 28, 2018,
licensed under
the MIT license
Copyright (c) 2018 K.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
;
const SHA224 = require("./SHA224-Node.js");
const assert = require("assert");
const every_buffers_equal = buffers =>
buffers.every(buffer => buffer.equals(buffers[0]));
// A test for the inputs
console.info("Testing the inputs.");
const input_set_1 = [
[[0xC0, 0xFF, 0xEE]],
[(new Uint8Array([0xC0, 0xFF, 0xEE])).buffer],
[(new Uint8Array([0xCA, 0xCA, 0x00, 0xC0, 0xFF, 0xEE])).buffer, 3],
[(new Uint8Array([0xC0, 0x01, 0xC0, 0xFF, 0xEE, 0xEE])).buffer, 2, 3],
[Buffer.from([0xC0, 0xFF, 0xEE])],
["C0FFEE", "hex"],
["C0ffee", "hex"],
["c0ffee", "hex"],
["wP/u", "base64"]
];
const input_set_2 = [
["Green chá"],
["Green chá", "utf8"],
["477265656e206368c3A1", "hex"],
["R3JlZW4gY2jDoQ==", "base64"]
];
const input_set_1_bufferified = input_set_1.map(args => Buffer.from(...args));
const input_set_2_bufferified = input_set_2.map(args => Buffer.from(...args));
assert.ok(every_buffers_equal(input_set_1_bufferified));
assert.ok(every_buffers_equal(input_set_2_bufferified));
// A test for the SHA-224 implementation
console.info("Testing the SHA-224 implementation.");
const input_set_1_sha224ed = input_set_1.map(args => SHA224(...args));
assert.ok(every_buffers_equal([
Buffer.from(
"26FB46CB822BA82F43339CB247EC" +
"D111770783F572A9B9A5CF34CD46",
"hex"
),
...input_set_1_sha224ed
]));
const input_set_2_sha224ed = input_set_2.map(args => SHA224(...args));
assert.ok(every_buffers_equal([
Buffer.from(
"0911CC3F1706191ADE7BCBADFA95" +
"1428F609CAA2F176E5F7E4FED6E7",
"hex"
),
...input_set_2_sha224ed
]));
console.info("No AssertionError? Great! :)");