mirror of
https://github.com/emn178/js-sha1.git
synced 2026-08-13 20:41:35 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65b3898c4e | ||
|
|
4ee5af05d3 | ||
|
|
c724643de0 |
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
|
/node_modules/
|
||||||
/tests/
|
/tests/
|
||||||
node_modules/
|
|
||||||
|
|||||||
+3
-3
@@ -1,3 +1,3 @@
|
|||||||
node_modules/
|
/node_modules/
|
||||||
covreporter
|
/coverage/
|
||||||
my_test
|
/.nyc_output/
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/node_modules/
|
||||||
|
/coverage/
|
||||||
|
/.nyc_output/
|
||||||
|
/tests/
|
||||||
|
.covignore
|
||||||
|
.travis.yml
|
||||||
|
.npmignore
|
||||||
|
bower.json
|
||||||
+3
-5
@@ -1,12 +1,10 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "0.12.15"
|
- "6.11.4"
|
||||||
- "4.5"
|
- "8.6.0"
|
||||||
- "6.5.0"
|
|
||||||
before_install:
|
before_install:
|
||||||
- npm install coveralls
|
- npm install coveralls
|
||||||
- npm install mocha-lcov-reporter
|
after_success: npm run coveralls
|
||||||
script: npm run-script coveralls
|
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
|
|||||||
@@ -1,5 +1,20 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## v0.6.0 / 2017-12-21
|
||||||
|
### Fixed
|
||||||
|
- incorrect result when first bit is 1 of bytes.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- prevent webpack to require dependencies.
|
||||||
|
|
||||||
|
## v0.5.0 / 2017-10-31
|
||||||
|
### Fixed
|
||||||
|
- incorrect result when file size >= 512M.
|
||||||
|
|
||||||
|
## v0.4.1 / 2016-12-30
|
||||||
|
### Fixed
|
||||||
|
- ArrayBuffer dosen't work in Webpack.
|
||||||
|
|
||||||
## v0.4.0 / 2016-12-05
|
## v0.4.0 / 2016-12-05
|
||||||
### Added
|
### Added
|
||||||
- update method.
|
- update method.
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
Copyright 2014-2016 Chen, Yi-Cyuan
|
Copyright 2014-2017 Chen, Yi-Cyuan
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "js-sha1",
|
"name": "js-sha1",
|
||||||
"version": "0.4.0",
|
"version": "0.6.0",
|
||||||
"main": ["src/sha1.js"],
|
"main": ["src/sha1.js"],
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"samples",
|
"samples",
|
||||||
|
|||||||
Vendored
+3
-3
File diff suppressed because one or more lines are too long
Generated
+1784
File diff suppressed because it is too large
Load Diff
+12
-7
@@ -1,20 +1,20 @@
|
|||||||
{
|
{
|
||||||
"name": "js-sha1",
|
"name": "js-sha1",
|
||||||
"version": "0.4.0",
|
"version": "0.6.0",
|
||||||
"description": "A simple SHA1 hash function for JavaScript supports UTF-8 encoding.",
|
"description": "A simple SHA1 hash function for JavaScript supports UTF-8 encoding.",
|
||||||
"main": "src/sha1.js",
|
"main": "src/sha1.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"expect.js": "~0.3.1",
|
"expect.js": "~0.3.1",
|
||||||
"jscoverage": "~0.5.9",
|
|
||||||
"mocha": "~2.3.4",
|
"mocha": "~2.3.4",
|
||||||
|
"nyc": "^11.3.0",
|
||||||
"requirejs": "^2.1.22",
|
"requirejs": "^2.1.22",
|
||||||
"uglifyjs": "~2.4.10"
|
"uglify-js": "^3.1.9"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha tests/node-test.js -r jscoverage",
|
"test": "nyc mocha tests/node-test.js",
|
||||||
"report": "mocha tests/node-test.js -r jscoverage --covout=html",
|
"report": "nyc --reporter=html --reporter=text mocha tests/node-test.js",
|
||||||
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls",
|
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
||||||
"build": "uglifyjs src/sha1.js --compress --mangle --comments --output build/sha1.min.js"
|
"build": "uglifyjs src/sha1.js -c -m eval --comments -o build/sha1.min.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -32,5 +32,10 @@
|
|||||||
"homepage": "https://github.com/emn178/js-sha1",
|
"homepage": "https://github.com/emn178/js-sha1",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/emn178/js-sha1/issues"
|
"url": "https://github.com/emn178/js-sha1/issues"
|
||||||
|
},
|
||||||
|
"nyc": {
|
||||||
|
"exclude": [
|
||||||
|
"tests"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,20 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
* [js-sha1]{@link https://github.com/emn178/js-sha1}
|
* [js-sha1]{@link https://github.com/emn178/js-sha1}
|
||||||
*
|
*
|
||||||
* @version 0.4.0
|
* @version 0.6.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2016
|
* @copyright Chen, Yi-Cyuan 2014-2017
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
(function(root) {
|
/*jslint bitwise: true */
|
||||||
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
|
var root = typeof window === 'object' ? window : {};
|
||||||
|
var NODE_JS = !root.JS_SHA1_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
|
||||||
if (NODE_JS) {
|
if (NODE_JS) {
|
||||||
root = global;
|
root = global;
|
||||||
}
|
}
|
||||||
var COMMON_JS = !root.JS_SHA1_TEST && typeof module == 'object' && module.exports;
|
var COMMON_JS = !root.JS_SHA1_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
||||||
var AMD = typeof define == 'function' && define.amd;
|
var AMD = typeof define === 'function' && define.amd;
|
||||||
var HEX_CHARS = '0123456789abcdef'.split('');
|
var HEX_CHARS = '0123456789abcdef'.split('');
|
||||||
var EXTRA = [-2147483648, 8388608, 32768, 128];
|
var EXTRA = [-2147483648, 8388608, 32768, 128];
|
||||||
var SHIFT = [24, 16, 8, 0];
|
var SHIFT = [24, 16, 8, 0];
|
||||||
@@ -47,21 +49,12 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var nodeWrap = function (method) {
|
var nodeWrap = function (method) {
|
||||||
var crypto, Buffer;
|
var crypto = eval("require('crypto')");
|
||||||
try {
|
var Buffer = eval("require('buffer').Buffer");
|
||||||
if (root.JS_SHA1_TEST) {
|
|
||||||
throw 'JS_SHA1_TEST';
|
|
||||||
}
|
|
||||||
crypto = require('crypto');
|
|
||||||
Buffer = require('buffer').Buffer;
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
return method;
|
|
||||||
}
|
|
||||||
var nodeMethod = function (message) {
|
var nodeMethod = function (message) {
|
||||||
if (typeof message == 'string') {
|
if (typeof message === 'string') {
|
||||||
return crypto.createHash('sha1').update(message, 'utf8').digest('hex');
|
return crypto.createHash('sha1').update(message, 'utf8').digest('hex');
|
||||||
} else if (message.constructor == ArrayBuffer) {
|
} else if (message.constructor === ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
} else if (message.length === undefined) {
|
} else if (message.length === undefined) {
|
||||||
return method(message);
|
return method(message);
|
||||||
@@ -88,7 +81,7 @@
|
|||||||
this.h3 = 0x10325476;
|
this.h3 = 0x10325476;
|
||||||
this.h4 = 0xC3D2E1F0;
|
this.h4 = 0xC3D2E1F0;
|
||||||
|
|
||||||
this.block = this.start = this.bytes = 0;
|
this.block = this.start = this.bytes = this.hBytes = 0;
|
||||||
this.finalized = this.hashed = false;
|
this.finalized = this.hashed = false;
|
||||||
this.first = true;
|
this.first = true;
|
||||||
}
|
}
|
||||||
@@ -97,8 +90,8 @@
|
|||||||
if (this.finalized) {
|
if (this.finalized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var notString = typeof(message) != 'string';
|
var notString = typeof(message) !== 'string';
|
||||||
if (notString && message.constructor == root.ArrayBuffer) {
|
if (notString && message.constructor === root.ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
}
|
}
|
||||||
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
|
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
|
||||||
@@ -150,6 +143,10 @@
|
|||||||
this.start = i;
|
this.start = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.bytes > 4294967295) {
|
||||||
|
this.hBytes += this.bytes / 4294967296 << 0;
|
||||||
|
this.bytes = this.bytes % 4294967296;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -172,6 +169,7 @@
|
|||||||
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
||||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||||
}
|
}
|
||||||
|
blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
|
||||||
blocks[15] = this.bytes << 3;
|
blocks[15] = this.bytes << 3;
|
||||||
this.hash();
|
this.hash();
|
||||||
};
|
};
|
||||||
@@ -370,4 +368,4 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(this));
|
})();
|
||||||
|
|||||||
+22
-4
@@ -1,12 +1,26 @@
|
|||||||
sha1 = require('../src/sha1.js');
|
// Node.js env
|
||||||
expect = require('expect.js');
|
expect = require('expect.js');
|
||||||
|
sha1 = require('../src/sha1.js');
|
||||||
require('./test.js');
|
require('./test.js');
|
||||||
|
|
||||||
delete require.cache[require.resolve('../src/sha1.js')]
|
delete require.cache[require.resolve('../src/sha1.js')];
|
||||||
delete require.cache[require.resolve('./test.js')]
|
delete require.cache[require.resolve('./test.js')];
|
||||||
sha1 = null;
|
sha1 = null;
|
||||||
|
|
||||||
JS_SHA1_TEST = true;
|
// Webpack browser env
|
||||||
|
JS_SHA1_NO_NODE_JS = true;
|
||||||
|
window = global;
|
||||||
|
sha1 = require('../src/sha1.js');
|
||||||
|
require('./test.js');
|
||||||
|
|
||||||
|
delete require.cache[require.resolve('../src/sha1.js')];
|
||||||
|
delete require.cache[require.resolve('./test.js')];
|
||||||
|
sha1 = null;
|
||||||
|
|
||||||
|
// browser env
|
||||||
|
JS_SHA1_NO_NODE_JS = true;
|
||||||
|
JS_SHA1_NO_COMMON_JS = true;
|
||||||
|
window = global;
|
||||||
require('../src/sha1.js');
|
require('../src/sha1.js');
|
||||||
require('./test.js');
|
require('./test.js');
|
||||||
|
|
||||||
@@ -14,6 +28,10 @@ delete require.cache[require.resolve('../src/sha1.js')];
|
|||||||
delete require.cache[require.resolve('./test.js')];
|
delete require.cache[require.resolve('./test.js')];
|
||||||
sha1 = null;
|
sha1 = null;
|
||||||
|
|
||||||
|
// browser AMD
|
||||||
|
JS_SHA1_NO_NODE_JS = true;
|
||||||
|
JS_SHA1_NO_COMMON_JS = true;
|
||||||
|
window = global;
|
||||||
define = function (func) {
|
define = function (func) {
|
||||||
sha1 = func();
|
sha1 = func();
|
||||||
require('./test.js');
|
require('./test.js');
|
||||||
|
|||||||
+8
-2
@@ -49,7 +49,6 @@
|
|||||||
'5ba93c9db0cff93f52b521d7420e43f6eda2784f': new ArrayBuffer(1)
|
'5ba93c9db0cff93f52b521d7420e43f6eda2784f': new ArrayBuffer(1)
|
||||||
},
|
},
|
||||||
'Object': {
|
'Object': {
|
||||||
'da39a3ee5e6b4b0d3255bfef95601890afd80709': {},
|
|
||||||
'da39a3ee5e6b4b0d3255bfef95601890afd80709': {what: 'ever'}
|
'da39a3ee5e6b4b0d3255bfef95601890afd80709': {what: 'ever'}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -58,7 +57,7 @@
|
|||||||
testCases['Buffer'] = {
|
testCases['Buffer'] = {
|
||||||
'da39a3ee5e6b4b0d3255bfef95601890afd80709': new Buffer(0),
|
'da39a3ee5e6b4b0d3255bfef95601890afd80709': new Buffer(0),
|
||||||
'2fd4e1c67a2d28fced849ee1bb76e7391b93eb12': new Buffer(new Uint8Array([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]))
|
'2fd4e1c67a2d28fced849ee1bb76e7391b93eb12': new Buffer(new Uint8Array([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 methods = [
|
var methods = [
|
||||||
@@ -176,5 +175,12 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
context('when large size', function () {
|
||||||
|
var hash = sha1.create();
|
||||||
|
hash.bytes = 4294967295;
|
||||||
|
hash.update('any');
|
||||||
|
expect(hash.hBytes).to.be(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
})(sha1);
|
})(sha1);
|
||||||
|
|||||||
Reference in New Issue
Block a user