Skip to content

Commit 61d4076

Browse files
author
Chen, Yi-Cyuan
committed
* Added some files to npm package.
* Updated coding style.
1 parent 1ff17fb commit 61d4076

File tree

10 files changed

+91
-121
lines changed

10 files changed

+91
-121
lines changed

.npmignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
covreporter
2-
build
3-
tests

.travis.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
language: node_js
22
node_js:
3-
- "0.11"
4-
- "0.10"
5-
- "0.8"
3+
- "0.12.15"
4+
- "4.5"
5+
- "6.5.0"
66
before_install:
7-
- npm install mocha -g
8-
- npm install coveralls -g
9-
- npm install mocha-lcov-reporter -g
7+
- npm install coveralls
8+
- npm install mocha-lcov-reporter
109
script: npm run-script coveralls
1110
branches:
1211
only:

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v0.3.1 / 2016-09-08
2+
3+
* Added some files to npm package.
4+
* Updated coding style.
5+
16
# v0.3.0 / 2015-05-23
27

38
* Support ArrayBuffer input.

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015 Chen Yi-Cyuan
1+
Copyright (c) 2014-2016 Chen, Yi-Cyuan
22

33
MIT License
44

README.md

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,40 +84,9 @@ Output
8484
[UTF8](http://jsperf.com/sha256/66)
8585
[ASCII](http://jsperf.com/sha256/65)
8686

87-
## Extensions
88-
### jQuery
89-
If you prefer jQuery style, you can add following code to add a jQuery extension.
90-
91-
Code
92-
```JavaScript
93-
jQuery.sha256 = sha256
94-
jQuery.sha224 = sha224
95-
```
96-
And then you could use like this:
97-
```JavaScript
98-
$.sha256('message');
99-
$.sha224('message');
100-
```
101-
### Prototype
102-
If you prefer prototype style, you can add following code to add a prototype extension.
103-
104-
Code
105-
```JavaScript
106-
String.prototype.sha256 = function() {
107-
return sha256(this);
108-
};
109-
String.prototype.sha224 = function() {
110-
return sha224(this);
111-
};
112-
```
113-
And then you could use like this:
114-
```JavaScript
115-
'message'.sha256();
116-
'message'.sha224();
117-
```
11887
## License
11988
The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).
12089

12190
## Contact
12291
The project's website is located at https://github.com/emn178/js-sha256
123-
92+
Author: Chen, Yi-Cyuan ([email protected])

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-sha256",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"main": ["src/sha256.js"],
55
"ignore": [
66
"samples",

build/sha256.min.js

Lines changed: 14 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "js-sha256",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "A simple SHA-256 / SHA-224 hash function for JavaScript supports UTF-8 encoding.",
55
"main": "src/sha256.js",
66
"devDependencies": {
7+
"mocha": "~2.3.4",
78
"expect.js": "~0.3.1",
89
"jscoverage": "~0.5.9"
910
},
@@ -26,7 +27,7 @@
2627
"HMAC"
2728
],
2829
"license": "MIT",
29-
"author": "emn178 <[email protected]>",
30+
"author": "Chen, Yi-Cyuan <[email protected]>",
3031
"homepage": "https://github.com/emn178/js-sha256",
3132
"bugs": {
3233
"url": "https://github.com/emn178/js-sha256/issues"

src/sha256.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
/*
2-
* js-sha256 v0.3.0
3-
* https://github.com/emn178/js-sha256
1+
/**
2+
* [js-sha256]{@link https://github.com/emn178/js-sha256}
43
*
5-
* Copyright 2014-2015, [email protected]
6-
*
7-
* Licensed under the MIT license:
8-
* http://www.opensource.org/licenses/MIT
4+
* @version 0.3.1
5+
* @author Chen, Yi-Cyuan [[email protected]]
6+
* @copyright Chen, Yi-Cyuan 2014-2016
7+
* @license MIT
98
*/
10-
;(function(root, undefined) {
9+
(function (root) {
1110
'use strict';
1211

13-
var NODE_JS = typeof(module) != 'undefined';
14-
if(NODE_JS) {
12+
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
13+
if (NODE_JS) {
1514
root = global;
1615
}
17-
var TYPED_ARRAY = typeof(Uint8Array) != 'undefined';
16+
var TYPED_ARRAY = typeof Uint8Array != 'undefined';
1817
var HEX_CHARS = '0123456789abcdef'.split('');
1918
var EXTRA = [-2147483648, 8388608, 32768, 128];
2019
var SHIFT = [24, 16, 8, 0];
@@ -29,21 +28,21 @@
2928

3029
var blocks = [];
3130

32-
var sha224 = function(message) {
31+
var sha224 = function (message) {
3332
return sha256(message, true);
3433
};
3534

36-
var sha256 = function(message, is224) {
37-
var notString = typeof(message) != 'string';
38-
if(notString && message.constructor == root.ArrayBuffer) {
35+
var sha256 = function (message, is224) {
36+
var notString = typeof message != 'string';
37+
if (notString && message.constructor == root.ArrayBuffer) {
3938
message = new Uint8Array(message);
4039
}
4140

4241
var h0, h1, h2, h3, h4, h5, h6, h7, block, code, first = true, end = false,
4342
i, j, index = 0, start = 0, bytes = 0, length = message.length,
4443
s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
4544

46-
if(is224) {
45+
if (is224) {
4746
h0 = 0xc1059ed8;
4847
h1 = 0x367cd507;
4948
h2 = 0x3070dd17;
@@ -69,12 +68,12 @@
6968
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
7069
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
7170
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
72-
if(notString) {
73-
for (i = start;index < length && i < 64; ++index) {
71+
if (notString) {
72+
for (i = start;index < length && i < 64;++index) {
7473
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
7574
}
7675
} else {
77-
for (i = start;index < length && i < 64; ++index) {
76+
for (i = start;index < length && i < 64;++index) {
7877
code = message.charCodeAt(index);
7978
if (code < 0x80) {
8079
blocks[i >> 2] |= code << SHIFT[i++ & 3];
@@ -96,18 +95,18 @@
9695
}
9796
bytes += i - start;
9897
start = i - 64;
99-
if(index == length) {
98+
if (index == length) {
10099
blocks[i >> 2] |= EXTRA[i & 3];
101100
++index;
102101
}
103102
block = blocks[16];
104-
if(index > length && i < 56) {
103+
if (index > length && i < 56) {
105104
blocks[15] = bytes << 3;
106105
end = true;
107106
}
108107

109108
var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7;
110-
for(j = 16;j < 64;++j) {
109+
for (j = 16;j < 64;++j) {
111110
// rightrotate
112111
t1 = blocks[j - 15];
113112
s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3);
@@ -117,9 +116,9 @@
117116
}
118117

119118
bc = b & c;
120-
for(j = 0;j < 64;j += 4) {
121-
if(first) {
122-
if(is224) {
119+
for (j = 0;j < 64;j += 4) {
120+
if (first) {
121+
if (is224) {
123122
ab = 300032;
124123
t1 = blocks[0] - 1413257819;
125124
h = t1 - 150054599 << 0;
@@ -179,7 +178,7 @@
179178
h5 = h5 + f << 0;
180179
h6 = h6 + g << 0;
181180
h7 = h7 + h << 0;
182-
} while(!end);
181+
} while (!end);
183182

184183
var hex = HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
185184
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
@@ -209,7 +208,7 @@
209208
HEX_CHARS[(h6 >> 20) & 0x0F] + HEX_CHARS[(h6 >> 16) & 0x0F] +
210209
HEX_CHARS[(h6 >> 12) & 0x0F] + HEX_CHARS[(h6 >> 8) & 0x0F] +
211210
HEX_CHARS[(h6 >> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F];
212-
if(!is224) {
211+
if (!is224) {
213212
hex += HEX_CHARS[(h7 >> 28) & 0x0F] + HEX_CHARS[(h7 >> 24) & 0x0F] +
214213
HEX_CHARS[(h7 >> 20) & 0x0F] + HEX_CHARS[(h7 >> 16) & 0x0F] +
215214
HEX_CHARS[(h7 >> 12) & 0x0F] + HEX_CHARS[(h7 >> 8) & 0x0F] +
@@ -218,11 +217,11 @@
218217
return hex;
219218
};
220219

221-
if(!root.JS_SHA256_TEST && NODE_JS) {
220+
if (!root.JS_SHA256_TEST && NODE_JS) {
222221
sha256.sha256 = sha256;
223222
sha256.sha224 = sha224;
224223
module.exports = sha256;
225-
} else if(root) {
224+
} else if (root) {
226225
root.sha256 = sha256;
227226
root.sha224 = sha224;
228227
}

0 commit comments

Comments
 (0)