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/
node_modules/

6
.gitignore vendored

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

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

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

@ -1,6 +1,6 @@
{
"name": "js-sha3",
"version": "0.5.6",
"version": "0.5.7",
"main": ["src/sha3.js"],
"ignore": [
"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",
"version": "0.5.6",
"version": "0.5.7",
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
"main": "src/sha3.js",
"typings": "index",
"types": "index.d.ts",
"devDependencies": {
"expect.js": "~0.3.1",
"jscoverage": "~0.5.9",
"mocha": "~2.3.2"
"mocha": "~2.3.2",
"uglifyjs": "~2.4.10"
},
"scripts": {
"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": {
"type": "git",

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

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

@ -2,7 +2,7 @@
Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () {
var array = new Uint8Array(this);
var hex = '';
for (var i = 0;i < array.length;++i) {
for (var i = 0; i < array.length; ++i) {
var c = array[i].toString('16');
hex += c.length == 1 ? '0' + c : c;
}
@ -264,7 +264,7 @@
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 hash = sha3_512.create();
for (var i = 0;i < bytes.length;++i) {
for (var i = 0; i < bytes.length; ++i) {
hash.update([bytes[i]]);
}
expect(hash.hex()).to.be('01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450');

Loading…
Cancel
Save