Compare commits
No commits in common. 'master' and 'v0.4.0' have entirely different histories.
@ -0,0 +1,2 @@
|
||||
/node_modules/
|
||||
/tests/
|
@ -1,3 +1,2 @@
|
||||
/node_modules/
|
||||
/coverage/
|
||||
/.nyc_output/
|
||||
/covreporter/
|
||||
|
@ -1,7 +0,0 @@
|
||||
/node_modules/
|
||||
/coverage/
|
||||
/.nyc_output/
|
||||
/tests/
|
||||
.travis.yml
|
||||
.npmignore
|
||||
bower.json
|
@ -1,10 +1,12 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "6.11.4"
|
||||
- "8.6.0"
|
||||
- "0.12.15"
|
||||
- "4.5"
|
||||
- "6.5.0"
|
||||
before_install:
|
||||
- npm install coveralls
|
||||
after_success: npm run coveralls
|
||||
- npm install mocha-lcov-reporter
|
||||
script: npm run-script coveralls
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,151 +0,0 @@
|
||||
type Message = string | number[] | ArrayBuffer | Uint8Array;
|
||||
|
||||
interface Hasher {
|
||||
/**
|
||||
* Update hash
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
update(message: Message): Hasher;
|
||||
|
||||
/**
|
||||
* Return hash in hex string.
|
||||
*/
|
||||
hex(): string;
|
||||
|
||||
/**
|
||||
* Return hash in hex string.
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/**
|
||||
* Return hash in ArrayBuffer.
|
||||
*/
|
||||
arrayBuffer(): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*/
|
||||
digest(): number[];
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*/
|
||||
array(): number[];
|
||||
}
|
||||
|
||||
interface Hmac {
|
||||
/**
|
||||
* Computes a Hash-based message authentication code (HMAC) using a secret key
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
(secretKey: string, message: Message): string;
|
||||
|
||||
/**
|
||||
* Create a hash object using a secret key.
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
*/
|
||||
create(secretKey: string): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object and hash message using a secret key
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
update(secretKey: string, message: Message): Hasher;
|
||||
|
||||
/**
|
||||
* Return hash in hex string.
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
hex(secretKey: string, message: Message): string;
|
||||
|
||||
/**
|
||||
* Return hash in ArrayBuffer.
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
arrayBuffer(secretKey: string, message: Message): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
digest(secretKey: string, message: Message): number[];
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
array(secretKey: string, message: Message): number[];
|
||||
}
|
||||
|
||||
interface Hash {
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
(message: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
hex(message: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return ArrayBuffer.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
arrayBuffer(message: Message): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
digest(message: Message): number[];
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
array(message: Message): number[];
|
||||
|
||||
/**
|
||||
* Create a hash object.
|
||||
*/
|
||||
create(): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object and hash message.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
update(message: Message): Hasher;
|
||||
|
||||
/**
|
||||
* HMAC interface
|
||||
*/
|
||||
hmac: Hmac;
|
||||
}
|
||||
|
||||
export var sha512: Hash;
|
||||
export var sha384: Hash;
|
||||
export var sha512_256: Hash;
|
||||
export var sha512_224: Hash;
|
File diff suppressed because it is too large
Load Diff
@ -1,290 +0,0 @@
|
||||
(function (sha512, sha384, sha512_256, sha512_224) {
|
||||
Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () {
|
||||
var array = new Uint8Array(this);
|
||||
var hex = '';
|
||||
for (var i = 0; i < array.length; ++i) {
|
||||
var c = array[i].toString('16');
|
||||
hex += c.length === 1 ? '0' + c : c;
|
||||
}
|
||||
return hex;
|
||||
};
|
||||
|
||||
var testCases = {
|
||||
sha512_hmac: {
|
||||
'Test Vectors': {
|
||||
'87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854': [
|
||||
[0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b],
|
||||
'Hi There'
|
||||
],
|
||||
'164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737': [
|
||||
'Jefe',
|
||||
'what do ya want for nothing?'
|
||||
],
|
||||
'fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb': [
|
||||
[0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526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598': [
|
||||
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
|
||||
'Test Using Larger Than Block-Size Key - Hash Key First'
|
||||
],
|
||||
'e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58': [
|
||||
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
|
||||
'This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm.'
|
||||
]
|
||||
},
|
||||
'UTF8': {
|
||||
'8a2f8205e690f84981727a6c49f8131d6a76030e39ba69e08adff7ab344c58ae1c20c22532b61d1f0410d3174e2b3f3dd08e9d1d82e86c960683eddf279a8239': ['中文', '中文'],
|
||||
'bb31bfef7be475a69f612741728c72237106053752a2804618c0b2d68cfe78cec6df18f4ae1fc0830f1153c1c497d817315c0129d84329b7f8c1d818306111d2': ['aécio', 'aécio'],
|
||||
'cba25df64cf81b67d2476bb812be931263561f219f423f723aa7be2e5c3cd3566a8adbc77663b6b6a69742f8f866f8afbff9b52769e2a53baae6d6a77d010c8a': ['𠜎', '𠜎']
|
||||
}
|
||||
},
|
||||
sha384_hmac: {
|
||||
'Test Vectors': {
|
||||
'afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6': [
|
||||
[0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b],
|
||||
'Hi There'
|
||||
],
|
||||
'af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649': [
|
||||
'Jefe',
|
||||
'what do ya want for nothing?'
|
||||
],
|
||||
'88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e55966144b2a5ab39dc13814b94e3ab6e101a34f27': [
|
||||
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
|
||||
[0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd]
|
||||
],
|
||||
'3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6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 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
|
||||
'This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm.'
|
||||
]
|
||||
},
|
||||
'UTF8': {
|
||||
'dd85fd0f7ae32037040ef2cfc344430addacf80f46f52c2ee066ab89ce6dedabb7d0a08cdb8765a7cfa616c7f4ddd377': ['中文', '中文'],
|
||||
'9f7abdeda88240304f987ecf11ceea9bd6571de782a2c73505f9dcaf9a58ec08cf69d078fc80d13ceb18e366f9537b0d': ['aécio', 'aécio'],
|
||||
'371f68d3377c583a29a38157348e4cc76d09aad3d86a5f4fdac661b2feefd7533338ffaf987267ac0ce3bb85e7787fce': ['𠜎', '𠜎']
|
||||
}
|
||||
},
|
||||
sha512_256_hmac: {
|
||||
'Test Vectors': {
|
||||
'9f9126c3d9c3c330d760425ca8a217e31feae31bfe70196ff81642b868402eab': [
|
||||
[0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b],
|
||||
'Hi There'
|
||||
],
|
||||
'6df7b24630d5ccb2ee335407081a87188c221489768fa2020513b2d593359456': [
|
||||
'Jefe',
|
||||
'what do ya want for nothing?'
|
||||
]
|
||||
}
|
||||
},
|
||||
sha512_224_hmac: {
|
||||
'Test Vectors': {
|
||||
'b244ba01307c0e7a8ccaad13b1067a4cf6b961fe0c6a20bda3d92039': [
|
||||
[0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b],
|
||||
'Hi There'
|
||||
],
|
||||
'4a530b31a79ebcce36916546317c45f247d83241dfb818fd37254bde': [
|
||||
'Jefe',
|
||||
'what do ya want for nothing?'
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (!(typeof JS_SHA512_NO_ARRAY_BUFFER === 'boolean' && JS_SHA512_NO_ARRAY_BUFFER)) {
|
||||
testCases.sha512_hmac['ArrayBuffer'] = {
|
||||
'f7688a104326d36c1940f6d28d746c0661d383e0d14fe8a04649444777610f5dd9565a36846ab9e9e734cf380d3a070d8ef021b5f3a50c481710a464968e3419': [
|
||||
new ArrayBuffer(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
testCases.sha512_hmac['Uint8Array'] = {
|
||||
'f7688a104326d36c1940f6d28d746c0661d383e0d14fe8a04649444777610f5dd9565a36846ab9e9e734cf380d3a070d8ef021b5f3a50c481710a464968e3419': [
|
||||
new Uint8Array(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
testCases.sha384_hmac['ArrayBuffer'] = {
|
||||
'da5393cef424a670d6db42c6ed6e7920779dfa4cbb98bf1c2e9c12ae10d10905d0c9e9d576c2a613be54b8daea246d4b': [
|
||||
new ArrayBuffer(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
testCases.sha384_hmac['Uint8Array'] = {
|
||||
'da5393cef424a670d6db42c6ed6e7920779dfa4cbb98bf1c2e9c12ae10d10905d0c9e9d576c2a613be54b8daea246d4b': [
|
||||
new Uint8Array(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
var errorTestCases = [null, undefined, { length: 0 }, 0, 1, false, true, NaN, Infinity, function () {}];
|
||||
|
||||
function runTestCases(name, algorithm) {
|
||||
var methods = [
|
||||
{
|
||||
name: name,
|
||||
call: algorithm,
|
||||
},
|
||||
{
|
||||
name: name + '.hex',
|
||||
call: algorithm.hex
|
||||
},
|
||||
{
|
||||
name: name + '.array',
|
||||
call: function (key, message) {
|
||||
return algorithm.array(key, message).toHexString();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: name + '.digest',
|
||||
call: function (key, message) {
|
||||
return algorithm.digest(key, message).toHexString();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: name + '.arrayBuffer',
|
||||
call: function (key, message) {
|
||||
return algorithm.arrayBuffer(key, message).toHexString();
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
var classMethods = [
|
||||
{
|
||||
name: 'create',
|
||||
call: function (key, message) {
|
||||
return algorithm.create(key).update(message).toString();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'update',
|
||||
call: function (key, message) {
|
||||
return algorithm.update(key, message).toString();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'hex',
|
||||
call: function (key, message) {
|
||||
return algorithm.update(key, message).hex();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'array',
|
||||
call: function (key, message) {
|
||||
return algorithm.update(key, message).array().toHexString();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'digest',
|
||||
call: function (key, message) {
|
||||
return algorithm.update(key, message).digest().toHexString();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'arrayBuffer',
|
||||
call: function (key, message) {
|
||||
return algorithm.update(key, message).arrayBuffer().toHexString();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'finalize',
|
||||
call: function (key, message) {
|
||||
var hash = algorithm.update(key, message);
|
||||
hash.hex();
|
||||
hash.finalize();
|
||||
return hash.hex();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'clone',
|
||||
call: function (key, message) {
|
||||
var hash = algorithm.update(key, message);
|
||||
var hash2 = hash.clone();
|
||||
hash.update('any');
|
||||
return hash2.hex();
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
var subTestCases = testCases[name];
|
||||
|
||||
describe(name, function () {
|
||||
methods.forEach(function (method) {
|
||||
describe('#' + method.name, function () {
|
||||
for (var testCaseName in subTestCases) {
|
||||
(function (testCaseName) {
|
||||
var testCase = subTestCases[testCaseName];
|
||||
context('when ' + testCaseName, function () {
|
||||
for (var hash in testCase) {
|
||||
(function (message, hash) {
|
||||
it('should be equal', function () {
|
||||
expect(method.call(message[0], message[1])).to.be(hash);
|
||||
});
|
||||
})(testCase[hash], hash);
|
||||
}
|
||||
});
|
||||
})(testCaseName);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
classMethods.forEach(function (method) {
|
||||
describe('#' + method.name, function () {
|
||||
for (var testCaseName in subTestCases) {
|
||||
(function (testCaseName) {
|
||||
var testCase = subTestCases[testCaseName];
|
||||
context('when ' + testCaseName, function () {
|
||||
for (var hash in testCase) {
|
||||
(function (message, hash) {
|
||||
it('should be equal', function () {
|
||||
expect(method.call(message[0], message[1])).to.be(hash);
|
||||
});
|
||||
})(testCase[hash], hash);
|
||||
}
|
||||
});
|
||||
})(testCaseName);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
context('when update after finalize', function () {
|
||||
it('should throw error', function () {
|
||||
expect(function () {
|
||||
var hash = algorithm.update('key', 'any');
|
||||
hash.hex();
|
||||
hash.update('any');
|
||||
}).to.throwError(/finalize already called/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#' + name, function () {
|
||||
errorTestCases.forEach(function (testCase) {
|
||||
context('when ' + testCase, function () {
|
||||
it('should throw error', function () {
|
||||
expect(function () {
|
||||
algorithm(testCase, '');
|
||||
}).to.throwError(/input is invalid type/);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
runTestCases('sha512_hmac', sha512.hmac);
|
||||
runTestCases('sha384_hmac', sha384.hmac);
|
||||
runTestCases('sha512_256_hmac', sha512_256.hmac);
|
||||
runTestCases('sha512_224_hmac', sha512_224.hmac);
|
||||
})(sha512, sha384, sha512_256, sha512_224);
|
@ -1,27 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>SHA512</title>
|
||||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
|
||||
<script src="../node_modules/mocha/mocha.js"></script>
|
||||
<script src="../node_modules/expect.js/index.js"></script>
|
||||
<script src="../node_modules/requirejs/require.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script>
|
||||
mocha.setup('bdd');
|
||||
require(['../src/sha512.js'], function (sha512) {
|
||||
window.sha512 = sha512;
|
||||
window.sha384 = sha512.sha384;
|
||||
window.sha512_256 = sha512.sha512_256;
|
||||
window.sha512_224 = sha512.sha512_224;
|
||||
require(['test.js'], function () {
|
||||
mocha.checkLeaks();
|
||||
mocha.run();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,24 +0,0 @@
|
||||
(function (Worker, WORKER, SOURCE) {
|
||||
var cases = {
|
||||
'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': '',
|
||||
'07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': 'The quick brown fox jumps over the lazy dog',
|
||||
'91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed': 'The quick brown fox jumps over the lazy dog.'
|
||||
};
|
||||
|
||||
describe('#sha512', function () {
|
||||
Object.keys(cases).forEach(function (hash) {
|
||||
it('should be equal', function (done) {
|
||||
var worker = new Worker(WORKER);
|
||||
worker.onmessage = function(event) {
|
||||
expect(event.data).to.be(hash);
|
||||
if (worker.terminate) {
|
||||
worker.terminate();
|
||||
}
|
||||
done();
|
||||
};
|
||||
worker.postMessage(SOURCE);
|
||||
worker.postMessage(cases[hash]);
|
||||
});
|
||||
});
|
||||
});
|
||||
})(Worker, WORKER, SOURCE);
|
@ -1,26 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>SHA512</title>
|
||||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
|
||||
<script src="../node_modules/mocha/mocha.js"></script>
|
||||
<script src="../node_modules/expect.js/index.js"></script>
|
||||
<script src="../src/sha512.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script>
|
||||
WORKER = 'worker.js';
|
||||
SOURCE = '../src/sha512.js';
|
||||
mocha.setup('bdd');
|
||||
</script>
|
||||
<script src="worker-test.js"></script>
|
||||
<script>
|
||||
mocha.checkLeaks();
|
||||
mocha.run();
|
||||
</script>
|
||||
<script>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,12 +0,0 @@
|
||||
var imported = false;
|
||||
onmessage = function(e) {
|
||||
if (imported) {
|
||||
postMessage(sha512(e.data));
|
||||
if (typeof exports !== 'undefined') {
|
||||
imported = false;
|
||||
}
|
||||
} else {
|
||||
imported = true;
|
||||
importScripts(e.data);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue