Comparing version 0.3.0 to 0.3.1
{ | ||
"name": "js-sha256", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"main": ["src/sha256.js"], | ||
@@ -5,0 +5,0 @@ "ignore": [ |
@@ -0,1 +1,6 @@ | ||
# v0.3.1 / 2016-09-08 | ||
* Added some files to npm package. | ||
* Updated coding style. | ||
# v0.3.0 / 2015-05-23 | ||
@@ -2,0 +7,0 @@ |
@@ -1,2 +0,2 @@ | ||
Copyright (c) 2015 Chen Yi-Cyuan | ||
Copyright (c) 2014-2016 Chen, Yi-Cyuan | ||
@@ -3,0 +3,0 @@ MIT License |
{ | ||
"name": "js-sha256", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "A simple SHA-256 / SHA-224 hash function for JavaScript supports UTF-8 encoding.", | ||
"main": "src/sha256.js", | ||
"devDependencies": { | ||
"mocha": "~2.3.4", | ||
"expect.js": "~0.3.1", | ||
@@ -29,3 +30,3 @@ "jscoverage": "~0.5.9" | ||
"license": "MIT", | ||
"author": "emn178 <emn178@gmail.com>", | ||
"author": "Chen, Yi-Cyuan <emn178@gmail.com>", | ||
"homepage": "https://github.com/emn178/js-sha256", | ||
@@ -32,0 +33,0 @@ "bugs": { |
@@ -87,33 +87,2 @@ # js-sha256 | ||
## Extensions | ||
### jQuery | ||
If you prefer jQuery style, you can add following code to add a jQuery extension. | ||
Code | ||
```JavaScript | ||
jQuery.sha256 = sha256 | ||
jQuery.sha224 = sha224 | ||
``` | ||
And then you could use like this: | ||
```JavaScript | ||
$.sha256('message'); | ||
$.sha224('message'); | ||
``` | ||
### Prototype | ||
If you prefer prototype style, you can add following code to add a prototype extension. | ||
Code | ||
```JavaScript | ||
String.prototype.sha256 = function() { | ||
return sha256(this); | ||
}; | ||
String.prototype.sha224 = function() { | ||
return sha224(this); | ||
}; | ||
``` | ||
And then you could use like this: | ||
```JavaScript | ||
'message'.sha256(); | ||
'message'.sha224(); | ||
``` | ||
## License | ||
@@ -124,2 +93,2 @@ The project is released under the [MIT license](http://www.opensource.org/licenses/MIT). | ||
The project's website is located at https://github.com/emn178/js-sha256 | ||
Author: emn178@gmail.com | ||
Author: Chen, Yi-Cyuan (emn178@gmail.com) |
@@ -1,18 +0,17 @@ | ||
/* | ||
* js-sha256 v0.3.0 | ||
* https://github.com/emn178/js-sha256 | ||
/** | ||
* [js-sha256]{@link https://github.com/emn178/js-sha256} | ||
* | ||
* Copyright 2014-2015, emn178@gmail.com | ||
* | ||
* Licensed under the MIT license: | ||
* http://www.opensource.org/licenses/MIT | ||
* @version 0.3.1 | ||
* @author Chen, Yi-Cyuan [emn178@gmail.com] | ||
* @copyright Chen, Yi-Cyuan 2014-2016 | ||
* @license MIT | ||
*/ | ||
;(function(root, undefined) { | ||
(function (root) { | ||
'use strict'; | ||
var NODE_JS = typeof(module) != 'undefined'; | ||
if(NODE_JS) { | ||
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node; | ||
if (NODE_JS) { | ||
root = global; | ||
} | ||
var TYPED_ARRAY = typeof(Uint8Array) != 'undefined'; | ||
var TYPED_ARRAY = typeof Uint8Array != 'undefined'; | ||
var HEX_CHARS = '0123456789abcdef'.split(''); | ||
@@ -32,9 +31,9 @@ var EXTRA = [-2147483648, 8388608, 32768, 128]; | ||
var sha224 = function(message) { | ||
var sha224 = function (message) { | ||
return sha256(message, true); | ||
}; | ||
var sha256 = function(message, is224) { | ||
var notString = typeof(message) != 'string'; | ||
if(notString && message.constructor == root.ArrayBuffer) { | ||
var sha256 = function (message, is224) { | ||
var notString = typeof message != 'string'; | ||
if (notString && message.constructor == root.ArrayBuffer) { | ||
message = new Uint8Array(message); | ||
@@ -47,3 +46,3 @@ } | ||
if(is224) { | ||
if (is224) { | ||
h0 = 0xc1059ed8; | ||
@@ -74,8 +73,8 @@ h1 = 0x367cd507; | ||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
if(notString) { | ||
for (i = start;index < length && i < 64; ++index) { | ||
if (notString) { | ||
for (i = start;index < length && i < 64;++index) { | ||
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; | ||
} | ||
} else { | ||
for (i = start;index < length && i < 64; ++index) { | ||
for (i = start;index < length && i < 64;++index) { | ||
code = message.charCodeAt(index); | ||
@@ -102,3 +101,3 @@ if (code < 0x80) { | ||
start = i - 64; | ||
if(index == length) { | ||
if (index == length) { | ||
blocks[i >> 2] |= EXTRA[i & 3]; | ||
@@ -108,3 +107,3 @@ ++index; | ||
block = blocks[16]; | ||
if(index > length && i < 56) { | ||
if (index > length && i < 56) { | ||
blocks[15] = bytes << 3; | ||
@@ -115,3 +114,3 @@ end = true; | ||
var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7; | ||
for(j = 16;j < 64;++j) { | ||
for (j = 16;j < 64;++j) { | ||
// rightrotate | ||
@@ -126,5 +125,5 @@ t1 = blocks[j - 15]; | ||
bc = b & c; | ||
for(j = 0;j < 64;j += 4) { | ||
if(first) { | ||
if(is224) { | ||
for (j = 0;j < 64;j += 4) { | ||
if (first) { | ||
if (is224) { | ||
ab = 300032; | ||
@@ -189,3 +188,3 @@ t1 = blocks[0] - 1413257819; | ||
h7 = h7 + h << 0; | ||
} while(!end); | ||
} while (!end); | ||
@@ -220,3 +219,3 @@ var hex = HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] + | ||
HEX_CHARS[(h6 >> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F]; | ||
if(!is224) { | ||
if (!is224) { | ||
hex += HEX_CHARS[(h7 >> 28) & 0x0F] + HEX_CHARS[(h7 >> 24) & 0x0F] + | ||
@@ -230,7 +229,7 @@ HEX_CHARS[(h7 >> 20) & 0x0F] + HEX_CHARS[(h7 >> 16) & 0x0F] + | ||
if(!root.JS_SHA256_TEST && NODE_JS) { | ||
if (!root.JS_SHA256_TEST && NODE_JS) { | ||
sha256.sha256 = sha256; | ||
sha256.sha224 = sha224; | ||
module.exports = sha256; | ||
} else if(root) { | ||
} else if (root) { | ||
root.sha256 = sha256; | ||
@@ -237,0 +236,0 @@ root.sha224 = sha224; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28356
13
368
3
93