Fixed ArrayBuffer detection in old browsers.

pull/12/head v0.5.7
Chen, Yi-Cyuan 9 years ago
parent 8ae70989ae
commit 5d6193d7f2

@ -1,2 +1,2 @@
/node_modules/
/tests/ /tests/
node_modules/

6
.gitignore vendored

@ -1,3 +1,3 @@
node_modules/ /node_modules/
covreporter /covreporter/
my_test /my_test/

@ -1,2 +0,0 @@
my_test
covreporter

@ -1,5 +1,9 @@
# Change Log # Change Log
## v0.5.7 / 2016-12-30
### Fixed
- ArrayBuffer detection in old browsers.
## v0.5.6 / 2016-12-29 ## v0.5.6 / 2016-12-29
### Fixed ### Fixed
- ArrayBuffer dosen't work in Webpack. - ArrayBuffer dosen't work in Webpack.

@ -1,6 +1,6 @@
{ {
"name": "js-sha3", "name": "js-sha3",
"version": "0.5.6", "version": "0.5.7",
"main": ["src/sha3.js"], "main": ["src/sha3.js"],
"ignore": [ "ignore": [
"samples", "samples",

17
build/sha3.min.js vendored

File diff suppressed because one or more lines are too long

@ -1,17 +1,21 @@
{ {
"name": "js-sha3", "name": "js-sha3",
"version": "0.5.6", "version": "0.5.7",
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.", "description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
"main": "src/sha3.js", "main": "src/sha3.js",
"typings": "index", "typings": "index",
"types": "index.d.ts",
"devDependencies": { "devDependencies": {
"expect.js": "~0.3.1", "expect.js": "~0.3.1",
"jscoverage": "~0.5.9", "jscoverage": "~0.5.9",
"mocha": "~2.3.2" "mocha": "~2.3.2",
"uglifyjs": "~2.4.10"
}, },
"scripts": { "scripts": {
"test": "mocha tests/node-test.js -r jscoverage", "test": "mocha tests/node-test.js -r jscoverage",
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls" "report": "mocha tests/node-test.js -r jscoverage --covout=html",
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls",
"build": "uglifyjs src/sha3.js --compress --mangle --comments --output build/sha3.min.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

@ -1,7 +1,7 @@
/** /**
* [js-sha3]{@link https://github.com/emn178/js-sha3} * [js-sha3]{@link https://github.com/emn178/js-sha3}
* *
* @version 0.5.6 * @version 0.5.7
* @author Chen, Yi-Cyuan [emn178@gmail.com] * @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2016 * @copyright Chen, Yi-Cyuan 2015-2016
* @license MIT * @license MIT
@ -109,8 +109,8 @@
} }
Keccak.prototype.update = function (message) { Keccak.prototype.update = function (message) {
var notString = typeof message != 'string'; var notString = typeof message !== 'string';
if (notString && message instanceof ArrayBuffer) { if (notString && message.constructor === ArrayBuffer) {
message = new Uint8Array(message); message = new Uint8Array(message);
} }
var length = message.length, blocks = this.blocks, byteCount = this.byteCount, var length = message.length, blocks = this.blocks, byteCount = this.byteCount,
@ -168,7 +168,7 @@
Keccak.prototype.finalize = function () { Keccak.prototype.finalize = function () {
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s; var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
blocks[i >> 2] |= this.padding[i & 3]; blocks[i >> 2] |= this.padding[i & 3];
if (this.lastByteIndex == this.byteCount) { if (this.lastByteIndex === this.byteCount) {
blocks[0] = blocks[blockCount]; blocks[0] = blocks[blockCount];
for (i = 1; i < blockCount + 1; ++i) { for (i = 1; i < blockCount + 1; ++i) {
blocks[i] = 0; blocks[i] = 0;

@ -1,5 +1,6 @@
// Node.js env
expect = require('expect.js'); expect = require('expect.js');
// Node.js env
var sha3 = require('../src/sha3.js'); var sha3 = require('../src/sha3.js');
keccak_512 = sha3.keccak_512; keccak_512 = sha3.keccak_512;
keccak_384 = sha3.keccak_384; keccak_384 = sha3.keccak_384;

@ -2,7 +2,7 @@
Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () { Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () {
var array = new Uint8Array(this); var array = new Uint8Array(this);
var hex = ''; var hex = '';
for (var i = 0;i < array.length;++i) { for (var i = 0; i < array.length; ++i) {
var c = array[i].toString('16'); var c = array[i].toString('16');
hex += c.length == 1 ? '0' + c : c; hex += c.length == 1 ? '0' + c : c;
} }
@ -87,7 +87,7 @@
}, },
'special length': { 'special length': {
'bce9da5b408846edd5bec9f26c2dee9bd835215c3f2b3876197067d87bc4d1af0cd97f94fda59761a0d804fe82383be2c6c4886fbb82e005fcf899449029f221' :'012345678901234567890123456789012345678901234567890123456789012345678901', 'bce9da5b408846edd5bec9f26c2dee9bd835215c3f2b3876197067d87bc4d1af0cd97f94fda59761a0d804fe82383be2c6c4886fbb82e005fcf899449029f221' :'012345678901234567890123456789012345678901234567890123456789012345678901',
'8bdcb85e6b52c29fafac0d3daf65492f2e3499e066da1a095a65eb1144849a26b2790a8b39c2a7fb747456f749391d953841a61cb13289f9806f04981c180a86' :'01234567890123456789012345678901234567890123456789012345678901234567890' '8bdcb85e6b52c29fafac0d3daf65492f2e3499e066da1a095a65eb1144849a26b2790a8b39c2a7fb747456f749391d953841a61cb13289f9806f04981c180a86' :'01234567890123456789012345678901234567890123456789012345678901234567890'
}, },
'Array': { 'Array': {
'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26': [], 'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26': [],
@ -264,7 +264,7 @@
it('should be equal', function () { it('should be equal', function () {
var bytes = [84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]; var bytes = [84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103];
var hash = sha3_512.create(); var hash = sha3_512.create();
for (var i = 0;i < bytes.length;++i) { for (var i = 0; i < bytes.length; ++i) {
hash.update([bytes[i]]); hash.update([bytes[i]]);
} }
expect(hash.hex()).to.be('01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450'); expect(hash.hex()).to.be('01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450');
@ -279,7 +279,7 @@
expect(keccak_512('01234567890123456789012345678901234567890123456789012345678901234567890')).to.be('3173e7abc754a0b2909410d78986428a9183e996864af02f421d273d9fa1b4e4a5b14e2998b20767712f53a01ff8f6ae2c3e71e51e2c0f24257b03e6da09eb77'); expect(keccak_512('01234567890123456789012345678901234567890123456789012345678901234567890')).to.be('3173e7abc754a0b2909410d78986428a9183e996864af02f421d273d9fa1b4e4a5b14e2998b20767712f53a01ff8f6ae2c3e71e51e2c0f24257b03e6da09eb77');
}); });
}); });
context('when Array', function () { context('when Array', function () {
it('should be equal', function () { it('should be equal', function () {
expect(keccak_512([])).to.be('0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e'); expect(keccak_512([])).to.be('0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e');

Loading…
Cancel
Save