From 8b9a23ce324d3af762796a41f6eb2b9a88ba7df2 Mon Sep 17 00:00:00 2001 From: "Chen, Yi-Cyuan" Date: Wed, 18 Jan 2017 09:44:08 +0800 Subject: [PATCH] Fixed `root` is undefined in some special environment. #7 --- .covignore | 2 +- .gitignore | 4 +- .travis.yml | 8 +-- CHANGELOG.md | 120 +++++++++++++++++++---------------- LICENSE.txt | 2 +- README.md | 4 -- bower.json | 2 +- build/md5.min.js | 6 +- doc/Md5_.html | 18 +++--- doc/global.html | 4 +- doc/index.html | 5 +- doc/md5.html | 20 +++--- doc/md5.js.html | 46 ++++++-------- doc/styles/jsdoc-default.css | 67 +++++++++---------- package.json | 2 +- src/md5.js | 44 ++++++------- tests/node-test.js | 35 +++++++++- tests/test.js | 2 +- 18 files changed, 206 insertions(+), 185 deletions(-) diff --git a/.covignore b/.covignore index 8c36f6f..c5e2446 100644 --- a/.covignore +++ b/.covignore @@ -1,2 +1,2 @@ +/node_modules/ /tests/ -node_modules/ diff --git a/.gitignore b/.gitignore index 5d763dc..856f74c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -covreporter -node_modules +/node_modules/ +/covreporter/ diff --git a/.travis.yml b/.travis.yml index 6d44cb9..4036a6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,8 @@ language: node_js node_js: - - "4.1" - - "4.0" - - "0.12" - - "0.11" - - "0.10" + - "0.12.15" + - "4.5" + - "6.5.0" before_install: - npm install coveralls - npm install mocha-lcov-reporter diff --git a/CHANGELOG.md b/CHANGELOG.md index f8f78ba..272b3f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,54 +1,66 @@ -# v0.4.1 / 2016-03-31 - -* Removed length detection in node.js. -* Deprecated `buffer` and replace by `arrayBuffer`. - -# v0.4.0 / 2015-12-28 - -* Added support for update hash. -* Added support for bytes array output. -* Added support for ArrayBuffer output. -* Added support for AMD. - -# v0.3.0 / 2015-03-07 - -* Support byte Array, Uint8Array and ArrayBuffer input. - -# v0.2.2 / 2015-02-01 - -* Fixed bug when special length. -* Improve performance for node.js. - -# v0.2.1 / 2015-01-13 - -* Improve performance. - -# v0.2.0 / 2015-01-12 - -* Remove ascii parameter. -* Improve performance. - -# v0.1.4 / 2015-01-11 - -* Improve performance. -* Add test case. - -# v0.1.3 / 2015-01-05 - -* Improve performance. -* Add bower package. -* Fixed JSHint warnings. -* Add travis. -* Add coveralls. - -# v0.1.2 / 2014-07-27 - -Fixed accents bug - -# v0.1.1 / 2014-01-05 - -Update license - -# v0.1.0 / 2014-01-04 - -Initial release +# Change Log + +## v0.4.2 / 2017-01-18 +### Fixed +- `root` is undefined in some special environment. #7 + +## v0.4.1 / 2016-03-31 +### Removed +- length detection in node.js. +### Deprecated +- `buffer` and replace by `arrayBuffer`. + +## v0.4.0 / 2015-12-28 +### Added +- support for update hash. +- support for bytes array output. +- support for ArrayBuffer output. +- support for AMD. + +## v0.3.0 / 2015-03-07 +### Added +- support byte Array, Uint8Array and ArrayBuffer input. + +## v0.2.2 / 2015-02-01 +### Fixed +- bug when special length. +### Improve +- performance for node.js. + +## v0.2.1 / 2015-01-13 +### Improve +- performance. + +## v0.2.0 / 2015-01-12 +### Removed +- ascii parameter. +### Improve +- performance. + +## v0.1.4 / 2015-01-11 +### Improve +- performance. +### Added +- test cases. + +## v0.1.3 / 2015-01-05 +### Added +- bower package. +- travis. +- coveralls. +### Improved +- performance. +### Fixed +- JSHint warnings. + +## v0.1.2 / 2014-07-27 +### Fixed +- accents bug + +## v0.1.1 / 2014-01-05 +### Changed +- license + +## v0.1.0 / 2014-01-04 +### Added +- initial release diff --git a/LICENSE.txt b/LICENSE.txt index 1598c37..74ac20d 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -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 a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index 2b4c023..e714046 100644 --- a/README.md +++ b/README.md @@ -67,10 +67,6 @@ md5.arrayBuffer(''); // ArrayBuffer md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead. ``` -## Benchmark -[UTF8](http://jsperf.com/md5-shootout/81) -[ASCII](http://jsperf.com/md5-shootout/82) - ## License The project is released under the [MIT license](http://www.opensource.org/licenses/MIT). diff --git a/bower.json b/bower.json index 98a50c4..591f9ad 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "js-md5", - "version": "0.4.1", + "version": "0.4.2", "main": ["src/md5.js"], "ignore": [ "tests" diff --git a/build/md5.min.js b/build/md5.min.js index 2694747..ceb0952 100644 --- a/build/md5.min.js +++ b/build/md5.min.js @@ -2,9 +2,9 @@ * [js-md5]{@link https://github.com/emn178/js-md5} * * @namespace md5 - * @version 0.4.1 + * @version 0.4.2 * @author Chen, Yi-Cyuan [emn178@gmail.com] - * @copyright Chen, Yi-Cyuan 2014-2016 + * @copyright Chen, Yi-Cyuan 2014-2017 * @license MIT */ -!function(t){"use strict";function r(t){if(t)c[0]=c[16]=c[1]=c[2]=c[3]=c[4]=c[5]=c[6]=c[7]=c[8]=c[9]=c[10]=c[11]=c[12]=c[13]=c[14]=c[15]=0,this.blocks=c,this.buffer8=i;else if(n){var r=new ArrayBuffer(68);this.buffer8=new Uint8Array(r),this.blocks=new Uint32Array(r)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=0,this.finalized=this.hashed=!1,this.first=!0}var e="object"==typeof process&&process.versions&&process.versions.node;e&&(t=global);var i,h=!t.JS_MD5_TEST&&"object"==typeof module&&module.exports,s="function"==typeof define&&define.amd,n=!t.JS_MD5_TEST&&"undefined"!=typeof ArrayBuffer,f="0123456789abcdef".split(""),a=[128,32768,8388608,-2147483648],o=[0,8,16,24],u=["hex","array","digest","buffer","arrayBuffer"],c=[];if(n){var p=new ArrayBuffer(68);i=new Uint8Array(p),c=new Uint32Array(p)}var y=function(t){return function(e){return new r(!0).update(e)[t]()}},d=function(){var t=y("hex");e&&(t=l(t)),t.create=function(){return new r},t.update=function(r){return t.create().update(r)};for(var i=0;is;){if(this.hashed&&(this.hashed=!1,a[0]=a[16],a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0),e)if(n)for(h=this.start;f>s&&64>h;++s)u[h++]=r[s];else for(h=this.start;f>s&&64>h;++s)a[h>>2]|=r[s]<s&&64>h;++s)i=r.charCodeAt(s),128>i?u[h++]=i:2048>i?(u[h++]=192|i>>6,u[h++]=128|63&i):55296>i||i>=57344?(u[h++]=224|i>>12,u[h++]=128|i>>6&63,u[h++]=128|63&i):(i=65536+((1023&i)<<10|1023&r.charCodeAt(++s)),u[h++]=240|i>>18,u[h++]=128|i>>12&63,u[h++]=128|i>>6&63,u[h++]=128|63&i);else for(h=this.start;f>s&&64>h;++s)i=r.charCodeAt(s),128>i?a[h>>2]|=i<i?(a[h>>2]|=(192|i>>6)<>2]|=(128|63&i)<i||i>=57344?(a[h>>2]|=(224|i>>12)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<>2]|=(240|i>>18)<>2]|=(128|i>>12&63)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<=64?(this.start=h-64,this.hash(),this.hashed=!0):this.start=h}return this}},r.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,r=this.lastByteIndex;t[r>>2]|=a[3&r],r>=56&&(this.hashed||this.hash(),t[0]=t[16],t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.bytes<<3,this.hash()}},r.prototype.hash=function(){var t,r,e,i,h,s,n=this.blocks;this.first?(t=n[0]-680876937,t=(t<<7|t>>>25)-271733879<<0,i=(-1732584194^2004318071&t)+n[1]-117830708,i=(i<<12|i>>>20)+t<<0,e=(-271733879^i&(-271733879^t))+n[2]-1126478375,e=(e<<17|e>>>15)+i<<0,r=(t^e&(i^t))+n[3]-1316259209,r=(r<<22|r>>>10)+e<<0):(t=this.h0,r=this.h1,e=this.h2,i=this.h3,t+=(i^r&(e^i))+n[0]-680876936,t=(t<<7|t>>>25)+r<<0,i+=(e^t&(r^e))+n[1]-389564586,i=(i<<12|i>>>20)+t<<0,e+=(r^i&(t^r))+n[2]+606105819,e=(e<<17|e>>>15)+i<<0,r+=(t^e&(i^t))+n[3]-1044525330,r=(r<<22|r>>>10)+e<<0),t+=(i^r&(e^i))+n[4]-176418897,t=(t<<7|t>>>25)+r<<0,i+=(e^t&(r^e))+n[5]+1200080426,i=(i<<12|i>>>20)+t<<0,e+=(r^i&(t^r))+n[6]-1473231341,e=(e<<17|e>>>15)+i<<0,r+=(t^e&(i^t))+n[7]-45705983,r=(r<<22|r>>>10)+e<<0,t+=(i^r&(e^i))+n[8]+1770035416,t=(t<<7|t>>>25)+r<<0,i+=(e^t&(r^e))+n[9]-1958414417,i=(i<<12|i>>>20)+t<<0,e+=(r^i&(t^r))+n[10]-42063,e=(e<<17|e>>>15)+i<<0,r+=(t^e&(i^t))+n[11]-1990404162,r=(r<<22|r>>>10)+e<<0,t+=(i^r&(e^i))+n[12]+1804603682,t=(t<<7|t>>>25)+r<<0,i+=(e^t&(r^e))+n[13]-40341101,i=(i<<12|i>>>20)+t<<0,e+=(r^i&(t^r))+n[14]-1502002290,e=(e<<17|e>>>15)+i<<0,r+=(t^e&(i^t))+n[15]+1236535329,r=(r<<22|r>>>10)+e<<0,t+=(e^i&(r^e))+n[1]-165796510,t=(t<<5|t>>>27)+r<<0,i+=(r^e&(t^r))+n[6]-1069501632,i=(i<<9|i>>>23)+t<<0,e+=(t^r&(i^t))+n[11]+643717713,e=(e<<14|e>>>18)+i<<0,r+=(i^t&(e^i))+n[0]-373897302,r=(r<<20|r>>>12)+e<<0,t+=(e^i&(r^e))+n[5]-701558691,t=(t<<5|t>>>27)+r<<0,i+=(r^e&(t^r))+n[10]+38016083,i=(i<<9|i>>>23)+t<<0,e+=(t^r&(i^t))+n[15]-660478335,e=(e<<14|e>>>18)+i<<0,r+=(i^t&(e^i))+n[4]-405537848,r=(r<<20|r>>>12)+e<<0,t+=(e^i&(r^e))+n[9]+568446438,t=(t<<5|t>>>27)+r<<0,i+=(r^e&(t^r))+n[14]-1019803690,i=(i<<9|i>>>23)+t<<0,e+=(t^r&(i^t))+n[3]-187363961,e=(e<<14|e>>>18)+i<<0,r+=(i^t&(e^i))+n[8]+1163531501,r=(r<<20|r>>>12)+e<<0,t+=(e^i&(r^e))+n[13]-1444681467,t=(t<<5|t>>>27)+r<<0,i+=(r^e&(t^r))+n[2]-51403784,i=(i<<9|i>>>23)+t<<0,e+=(t^r&(i^t))+n[7]+1735328473,e=(e<<14|e>>>18)+i<<0,r+=(i^t&(e^i))+n[12]-1926607734,r=(r<<20|r>>>12)+e<<0,h=r^e,t+=(h^i)+n[5]-378558,t=(t<<4|t>>>28)+r<<0,i+=(h^t)+n[8]-2022574463,i=(i<<11|i>>>21)+t<<0,s=i^t,e+=(s^r)+n[11]+1839030562,e=(e<<16|e>>>16)+i<<0,r+=(s^e)+n[14]-35309556,r=(r<<23|r>>>9)+e<<0,h=r^e,t+=(h^i)+n[1]-1530992060,t=(t<<4|t>>>28)+r<<0,i+=(h^t)+n[4]+1272893353,i=(i<<11|i>>>21)+t<<0,s=i^t,e+=(s^r)+n[7]-155497632,e=(e<<16|e>>>16)+i<<0,r+=(s^e)+n[10]-1094730640,r=(r<<23|r>>>9)+e<<0,h=r^e,t+=(h^i)+n[13]+681279174,t=(t<<4|t>>>28)+r<<0,i+=(h^t)+n[0]-358537222,i=(i<<11|i>>>21)+t<<0,s=i^t,e+=(s^r)+n[3]-722521979,e=(e<<16|e>>>16)+i<<0,r+=(s^e)+n[6]+76029189,r=(r<<23|r>>>9)+e<<0,h=r^e,t+=(h^i)+n[9]-640364487,t=(t<<4|t>>>28)+r<<0,i+=(h^t)+n[12]-421815835,i=(i<<11|i>>>21)+t<<0,s=i^t,e+=(s^r)+n[15]+530742520,e=(e<<16|e>>>16)+i<<0,r+=(s^e)+n[2]-995338651,r=(r<<23|r>>>9)+e<<0,t+=(e^(r|~i))+n[0]-198630844,t=(t<<6|t>>>26)+r<<0,i+=(r^(t|~e))+n[7]+1126891415,i=(i<<10|i>>>22)+t<<0,e+=(t^(i|~r))+n[14]-1416354905,e=(e<<15|e>>>17)+i<<0,r+=(i^(e|~t))+n[5]-57434055,r=(r<<21|r>>>11)+e<<0,t+=(e^(r|~i))+n[12]+1700485571,t=(t<<6|t>>>26)+r<<0,i+=(r^(t|~e))+n[3]-1894986606,i=(i<<10|i>>>22)+t<<0,e+=(t^(i|~r))+n[10]-1051523,e=(e<<15|e>>>17)+i<<0,r+=(i^(e|~t))+n[1]-2054922799,r=(r<<21|r>>>11)+e<<0,t+=(e^(r|~i))+n[8]+1873313359,t=(t<<6|t>>>26)+r<<0,i+=(r^(t|~e))+n[15]-30611744,i=(i<<10|i>>>22)+t<<0,e+=(t^(i|~r))+n[6]-1560198380,e=(e<<15|e>>>17)+i<<0,r+=(i^(e|~t))+n[13]+1309151649,r=(r<<21|r>>>11)+e<<0,t+=(e^(r|~i))+n[4]-145523070,t=(t<<6|t>>>26)+r<<0,i+=(r^(t|~e))+n[11]-1120210379,i=(i<<10|i>>>22)+t<<0,e+=(t^(i|~r))+n[2]+718787259,e=(e<<15|e>>>17)+i<<0,r+=(i^(e|~t))+n[9]-343485551,r=(r<<21|r>>>11)+e<<0,this.first?(this.h0=t+1732584193<<0,this.h1=r-271733879<<0,this.h2=e-1732584194<<0,this.h3=i+271733878<<0,this.first=!1):(this.h0=this.h0+t<<0,this.h1=this.h1+r<<0,this.h2=this.h2+e<<0,this.h3=this.h3+i<<0)},r.prototype.hex=function(){this.finalize();var t=this.h0,r=this.h1,e=this.h2,i=this.h3;return f[t>>4&15]+f[15&t]+f[t>>12&15]+f[t>>8&15]+f[t>>20&15]+f[t>>16&15]+f[t>>28&15]+f[t>>24&15]+f[r>>4&15]+f[15&r]+f[r>>12&15]+f[r>>8&15]+f[r>>20&15]+f[r>>16&15]+f[r>>28&15]+f[r>>24&15]+f[e>>4&15]+f[15&e]+f[e>>12&15]+f[e>>8&15]+f[e>>20&15]+f[e>>16&15]+f[e>>28&15]+f[e>>24&15]+f[i>>4&15]+f[15&i]+f[i>>12&15]+f[i>>8&15]+f[i>>20&15]+f[i>>16&15]+f[i>>28&15]+f[i>>24&15]},r.prototype.toString=r.prototype.hex,r.prototype.digest=function(){this.finalize();var t=this.h0,r=this.h1,e=this.h2,i=this.h3;return[255&t,t>>8&255,t>>16&255,t>>24&255,255&r,r>>8&255,r>>16&255,r>>24&255,255&e,e>>8&255,e>>16&255,e>>24&255,255&i,i>>8&255,i>>16&255,i>>24&255]},r.prototype.array=r.prototype.digest,r.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(16),r=new Uint32Array(t);return r[0]=this.h0,r[1]=this.h1,r[2]=this.h2,r[3]=this.h3,t},r.prototype.buffer=r.prototype.arrayBuffer;var v=d();h?module.exports=v:(t.md5=v,s&&define(function(){return v}))}(this); +!function(){"use strict";function t(t){if(t)c[0]=c[16]=c[1]=c[2]=c[3]=c[4]=c[5]=c[6]=c[7]=c[8]=c[9]=c[10]=c[11]=c[12]=c[13]=c[14]=c[15]=0,this.blocks=c,this.buffer8=i;else if(n){var r=new ArrayBuffer(68);this.buffer8=new Uint8Array(r),this.blocks=new Uint32Array(r)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=0,this.finalized=this.hashed=!1,this.first=!0}var r="object"==typeof window?window:{},e=!r.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;e&&(r=global);var i,h=!r.JS_MD5_NO_COMMON_JS&&"object"==typeof module&&module.exports,s="function"==typeof define&&define.amd,n=!r.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,f="0123456789abcdef".split(""),o=[128,32768,8388608,-2147483648],a=[0,8,16,24],u=["hex","array","digest","buffer","arrayBuffer"],c=[];if(n){var p=new ArrayBuffer(68);i=new Uint8Array(p),c=new Uint32Array(p)}var d=function(r){return function(e){return new t(!0).update(e)[r]()}},y=function(){var r=d("hex");e&&(r=l(r)),r.create=function(){return new t},r.update=function(t){return r.create().update(t)};for(var i=0;is;){if(this.hashed&&(this.hashed=!1,o[0]=o[16],o[16]=o[1]=o[2]=o[3]=o[4]=o[5]=o[6]=o[7]=o[8]=o[9]=o[10]=o[11]=o[12]=o[13]=o[14]=o[15]=0),e)if(n)for(h=this.start;f>s&&64>h;++s)u[h++]=t[s];else for(h=this.start;f>s&&64>h;++s)o[h>>2]|=t[s]<s&&64>h;++s)i=t.charCodeAt(s),128>i?u[h++]=i:2048>i?(u[h++]=192|i>>6,u[h++]=128|63&i):55296>i||i>=57344?(u[h++]=224|i>>12,u[h++]=128|i>>6&63,u[h++]=128|63&i):(i=65536+((1023&i)<<10|1023&t.charCodeAt(++s)),u[h++]=240|i>>18,u[h++]=128|i>>12&63,u[h++]=128|i>>6&63,u[h++]=128|63&i);else for(h=this.start;f>s&&64>h;++s)i=t.charCodeAt(s),128>i?o[h>>2]|=i<i?(o[h>>2]|=(192|i>>6)<>2]|=(128|63&i)<i||i>=57344?(o[h>>2]|=(224|i>>12)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<>2]|=(240|i>>18)<>2]|=(128|i>>12&63)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<=64?(this.start=h-64,this.hash(),this.hashed=!0):this.start=h}return this}},t.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,r=this.lastByteIndex;t[r>>2]|=o[3&r],r>=56&&(this.hashed||this.hash(),t[0]=t[16],t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.bytes<<3,this.hash()}},t.prototype.hash=function(){var t,r,e,i,h,s,n=this.blocks;this.first?(t=n[0]-680876937,t=(t<<7|t>>>25)-271733879<<0,i=(-1732584194^2004318071&t)+n[1]-117830708,i=(i<<12|i>>>20)+t<<0,e=(-271733879^i&(-271733879^t))+n[2]-1126478375,e=(e<<17|e>>>15)+i<<0,r=(t^e&(i^t))+n[3]-1316259209,r=(r<<22|r>>>10)+e<<0):(t=this.h0,r=this.h1,e=this.h2,i=this.h3,t+=(i^r&(e^i))+n[0]-680876936,t=(t<<7|t>>>25)+r<<0,i+=(e^t&(r^e))+n[1]-389564586,i=(i<<12|i>>>20)+t<<0,e+=(r^i&(t^r))+n[2]+606105819,e=(e<<17|e>>>15)+i<<0,r+=(t^e&(i^t))+n[3]-1044525330,r=(r<<22|r>>>10)+e<<0),t+=(i^r&(e^i))+n[4]-176418897,t=(t<<7|t>>>25)+r<<0,i+=(e^t&(r^e))+n[5]+1200080426,i=(i<<12|i>>>20)+t<<0,e+=(r^i&(t^r))+n[6]-1473231341,e=(e<<17|e>>>15)+i<<0,r+=(t^e&(i^t))+n[7]-45705983,r=(r<<22|r>>>10)+e<<0,t+=(i^r&(e^i))+n[8]+1770035416,t=(t<<7|t>>>25)+r<<0,i+=(e^t&(r^e))+n[9]-1958414417,i=(i<<12|i>>>20)+t<<0,e+=(r^i&(t^r))+n[10]-42063,e=(e<<17|e>>>15)+i<<0,r+=(t^e&(i^t))+n[11]-1990404162,r=(r<<22|r>>>10)+e<<0,t+=(i^r&(e^i))+n[12]+1804603682,t=(t<<7|t>>>25)+r<<0,i+=(e^t&(r^e))+n[13]-40341101,i=(i<<12|i>>>20)+t<<0,e+=(r^i&(t^r))+n[14]-1502002290,e=(e<<17|e>>>15)+i<<0,r+=(t^e&(i^t))+n[15]+1236535329,r=(r<<22|r>>>10)+e<<0,t+=(e^i&(r^e))+n[1]-165796510,t=(t<<5|t>>>27)+r<<0,i+=(r^e&(t^r))+n[6]-1069501632,i=(i<<9|i>>>23)+t<<0,e+=(t^r&(i^t))+n[11]+643717713,e=(e<<14|e>>>18)+i<<0,r+=(i^t&(e^i))+n[0]-373897302,r=(r<<20|r>>>12)+e<<0,t+=(e^i&(r^e))+n[5]-701558691,t=(t<<5|t>>>27)+r<<0,i+=(r^e&(t^r))+n[10]+38016083,i=(i<<9|i>>>23)+t<<0,e+=(t^r&(i^t))+n[15]-660478335,e=(e<<14|e>>>18)+i<<0,r+=(i^t&(e^i))+n[4]-405537848,r=(r<<20|r>>>12)+e<<0,t+=(e^i&(r^e))+n[9]+568446438,t=(t<<5|t>>>27)+r<<0,i+=(r^e&(t^r))+n[14]-1019803690,i=(i<<9|i>>>23)+t<<0,e+=(t^r&(i^t))+n[3]-187363961,e=(e<<14|e>>>18)+i<<0,r+=(i^t&(e^i))+n[8]+1163531501,r=(r<<20|r>>>12)+e<<0,t+=(e^i&(r^e))+n[13]-1444681467,t=(t<<5|t>>>27)+r<<0,i+=(r^e&(t^r))+n[2]-51403784,i=(i<<9|i>>>23)+t<<0,e+=(t^r&(i^t))+n[7]+1735328473,e=(e<<14|e>>>18)+i<<0,r+=(i^t&(e^i))+n[12]-1926607734,r=(r<<20|r>>>12)+e<<0,h=r^e,t+=(h^i)+n[5]-378558,t=(t<<4|t>>>28)+r<<0,i+=(h^t)+n[8]-2022574463,i=(i<<11|i>>>21)+t<<0,s=i^t,e+=(s^r)+n[11]+1839030562,e=(e<<16|e>>>16)+i<<0,r+=(s^e)+n[14]-35309556,r=(r<<23|r>>>9)+e<<0,h=r^e,t+=(h^i)+n[1]-1530992060,t=(t<<4|t>>>28)+r<<0,i+=(h^t)+n[4]+1272893353,i=(i<<11|i>>>21)+t<<0,s=i^t,e+=(s^r)+n[7]-155497632,e=(e<<16|e>>>16)+i<<0,r+=(s^e)+n[10]-1094730640,r=(r<<23|r>>>9)+e<<0,h=r^e,t+=(h^i)+n[13]+681279174,t=(t<<4|t>>>28)+r<<0,i+=(h^t)+n[0]-358537222,i=(i<<11|i>>>21)+t<<0,s=i^t,e+=(s^r)+n[3]-722521979,e=(e<<16|e>>>16)+i<<0,r+=(s^e)+n[6]+76029189,r=(r<<23|r>>>9)+e<<0,h=r^e,t+=(h^i)+n[9]-640364487,t=(t<<4|t>>>28)+r<<0,i+=(h^t)+n[12]-421815835,i=(i<<11|i>>>21)+t<<0,s=i^t,e+=(s^r)+n[15]+530742520,e=(e<<16|e>>>16)+i<<0,r+=(s^e)+n[2]-995338651,r=(r<<23|r>>>9)+e<<0,t+=(e^(r|~i))+n[0]-198630844,t=(t<<6|t>>>26)+r<<0,i+=(r^(t|~e))+n[7]+1126891415,i=(i<<10|i>>>22)+t<<0,e+=(t^(i|~r))+n[14]-1416354905,e=(e<<15|e>>>17)+i<<0,r+=(i^(e|~t))+n[5]-57434055,r=(r<<21|r>>>11)+e<<0,t+=(e^(r|~i))+n[12]+1700485571,t=(t<<6|t>>>26)+r<<0,i+=(r^(t|~e))+n[3]-1894986606,i=(i<<10|i>>>22)+t<<0,e+=(t^(i|~r))+n[10]-1051523,e=(e<<15|e>>>17)+i<<0,r+=(i^(e|~t))+n[1]-2054922799,r=(r<<21|r>>>11)+e<<0,t+=(e^(r|~i))+n[8]+1873313359,t=(t<<6|t>>>26)+r<<0,i+=(r^(t|~e))+n[15]-30611744,i=(i<<10|i>>>22)+t<<0,e+=(t^(i|~r))+n[6]-1560198380,e=(e<<15|e>>>17)+i<<0,r+=(i^(e|~t))+n[13]+1309151649,r=(r<<21|r>>>11)+e<<0,t+=(e^(r|~i))+n[4]-145523070,t=(t<<6|t>>>26)+r<<0,i+=(r^(t|~e))+n[11]-1120210379,i=(i<<10|i>>>22)+t<<0,e+=(t^(i|~r))+n[2]+718787259,e=(e<<15|e>>>17)+i<<0,r+=(i^(e|~t))+n[9]-343485551,r=(r<<21|r>>>11)+e<<0,this.first?(this.h0=t+1732584193<<0,this.h1=r-271733879<<0,this.h2=e-1732584194<<0,this.h3=i+271733878<<0,this.first=!1):(this.h0=this.h0+t<<0,this.h1=this.h1+r<<0,this.h2=this.h2+e<<0,this.h3=this.h3+i<<0)},t.prototype.hex=function(){this.finalize();var t=this.h0,r=this.h1,e=this.h2,i=this.h3;return f[t>>4&15]+f[15&t]+f[t>>12&15]+f[t>>8&15]+f[t>>20&15]+f[t>>16&15]+f[t>>28&15]+f[t>>24&15]+f[r>>4&15]+f[15&r]+f[r>>12&15]+f[r>>8&15]+f[r>>20&15]+f[r>>16&15]+f[r>>28&15]+f[r>>24&15]+f[e>>4&15]+f[15&e]+f[e>>12&15]+f[e>>8&15]+f[e>>20&15]+f[e>>16&15]+f[e>>28&15]+f[e>>24&15]+f[i>>4&15]+f[15&i]+f[i>>12&15]+f[i>>8&15]+f[i>>20&15]+f[i>>16&15]+f[i>>28&15]+f[i>>24&15]},t.prototype.toString=t.prototype.hex,t.prototype.digest=function(){this.finalize();var t=this.h0,r=this.h1,e=this.h2,i=this.h3;return[255&t,t>>8&255,t>>16&255,t>>24&255,255&r,r>>8&255,r>>16&255,r>>24&255,255&e,e>>8&255,e>>16&255,e>>24&255,255&i,i>>8&255,i>>16&255,i>>24&255]},t.prototype.array=t.prototype.digest,t.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(16),r=new Uint32Array(t);return r[0]=this.h0,r[1]=this.h1,r[2]=this.h2,r[3]=this.h3,t},t.prototype.buffer=t.prototype.arrayBuffer;var b=y();h?module.exports=b:(r.md5=b,s&&define(function(){return b}))}(); \ No newline at end of file diff --git a/doc/Md5_.html b/doc/Md5_.html index 852f389..482b4d7 100644 --- a/doc/Md5_.html +++ b/doc/Md5_.html @@ -91,7 +91,7 @@
Source:
@@ -198,7 +198,7 @@
Source:
@@ -314,7 +314,7 @@
Source:
@@ -432,7 +432,7 @@
Source:
@@ -548,7 +548,7 @@
Source:
@@ -664,7 +664,7 @@
Source:
@@ -780,7 +780,7 @@
Source:
@@ -954,7 +954,7 @@
Source:
@@ -1031,7 +1031,7 @@
- Documentation generated by JSDoc 3.4.0 on Thu Mar 31 2016 16:24:21 GMT+0800 (CST) + Documentation generated by JSDoc 3.4.3 on Wed Jan 18 2017 09:43:27 GMT+0800 (CST)
diff --git a/doc/global.html b/doc/global.html index c4a5a52..288d0de 100644 --- a/doc/global.html +++ b/doc/global.html @@ -210,7 +210,7 @@
Source:
@@ -285,7 +285,7 @@
- Documentation generated by JSDoc 3.4.0 on Thu Mar 31 2016 16:24:21 GMT+0800 (CST) + Documentation generated by JSDoc 3.4.3 on Wed Jan 18 2017 09:43:27 GMT+0800 (CST)
diff --git a/doc/index.html b/doc/index.html index 237a007..cf3ad97 100644 --- a/doc/index.html +++ b/doc/index.html @@ -77,8 +77,7 @@ md5.hex(''); // d41d8cd98f00b204e9800998ecf8427e md5.array(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126] md5.digest(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126] md5.arrayBuffer(''); // ArrayBuffer -md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.

Benchmark

UTF8
ASCII

-

License

The project is released under the MIT license.

+md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.

License

The project is released under the MIT license.

Contact

The project's website is located at https://github.com/emn178/js-md5
Author: Chen, Yi-Cyuan (emn178@gmail.com)

@@ -96,7 +95,7 @@ md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in no
- Documentation generated by JSDoc 3.4.0 on Thu Mar 31 2016 16:24:21 GMT+0800 (CST) + Documentation generated by JSDoc 3.4.3 on Wed Jan 18 2017 09:43:27 GMT+0800 (CST)
diff --git a/doc/md5.html b/doc/md5.html index 58b92fa..177ce88 100644 --- a/doc/md5.html +++ b/doc/md5.html @@ -47,7 +47,7 @@
Version:
-
  • 0.4.0
+
  • 0.4.2
@@ -75,7 +75,7 @@ - + @@ -233,7 +233,7 @@
Source:
@@ -400,7 +400,7 @@
Source:
@@ -569,7 +569,7 @@
Source:
@@ -678,7 +678,7 @@
Source:
@@ -845,7 +845,7 @@
Source:
@@ -1012,7 +1012,7 @@
Source:
@@ -1179,7 +1179,7 @@
Source:
@@ -1254,7 +1254,7 @@
- Documentation generated by JSDoc 3.4.0 on Thu Mar 31 2016 16:24:21 GMT+0800 (CST) + Documentation generated by JSDoc 3.4.3 on Wed Jan 18 2017 09:43:27 GMT+0800 (CST)
diff --git a/doc/md5.js.html b/doc/md5.js.html index 749ddd6..b50da70 100644 --- a/doc/md5.js.html +++ b/doc/md5.js.html @@ -30,21 +30,22 @@ * [js-md5]{@link https://github.com/emn178/js-md5} * * @namespace md5 - * @version 0.4.0 + * @version 0.4.2 * @author Chen, Yi-Cyuan [emn178@gmail.com] - * @copyright Chen, Yi-Cyuan 2014-2016 + * @copyright Chen, Yi-Cyuan 2014-2017 * @license MIT */ -(function (root) { +(function () { 'use strict'; - var NODE_JS = typeof process == 'object' && process.versions && process.versions.node; + var root = typeof window === 'object' ? window : {}; + var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node; if (NODE_JS) { root = global; } - var COMMON_JS = !root.JS_MD5_TEST && typeof module == 'object' && module.exports; - var AMD = typeof define == 'function' && define.amd; - var ARRAY_BUFFER = !root.JS_MD5_TEST && typeof ArrayBuffer != 'undefined'; + var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && typeof module === 'object' && module.exports; + var AMD = typeof define === 'function' && define.amd; + var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined'; var HEX_CHARS = '0123456789abcdef'.split(''); var EXTRA = [128, 32768, 8388608, -2147483648]; var SHIFT = [0, 8, 16, 24]; @@ -142,7 +143,7 @@ method.update = function (message) { return method.create().update(message); }; - for (var i = 0;i < OUTPUT_TYPES.length;++i) { + for (var i = 0; i < OUTPUT_TYPES.length; ++i) { var type = OUTPUT_TYPES[i]; method[type] = createOutputMethod(type); } @@ -150,21 +151,12 @@ }; var nodeWrap = function (method) { - var crypto, Buffer; - try { - if (root.JS_MD5_TEST) { - throw 'JS_MD5_TEST'; - } - crypto = require('crypto'); - Buffer = require('buffer').Buffer; - } catch (e) { - console.log(e); - return method; - } + var crypto = require('crypto'); + var Buffer = require('buffer').Buffer; var nodeMethod = function (message) { - if (typeof message == 'string') { + if (typeof message === 'string') { return crypto.createHash('md5').update(message, 'utf8').digest('hex'); - } else if (message.constructor == ArrayBuffer) { + } else if (message.constructor === ArrayBuffer) { message = new Uint8Array(message); } else if (message.length === undefined) { return method(message); @@ -234,17 +226,17 @@ if (notString) { if (ARRAY_BUFFER) { - for (i = this.start;index < length && i < 64; ++index) { + for (i = this.start; index < length && i < 64; ++index) { buffer8[i++] = message[index]; } } else { - for (i = this.start;index < length && i < 64; ++index) { + for (i = this.start; index < length && i < 64; ++index) { blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; } } } else { if (ARRAY_BUFFER) { - for (i = this.start;index < length && i < 64; ++index) { + for (i = this.start; index < length && i < 64; ++index) { code = message.charCodeAt(index); if (code < 0x80) { buffer8[i++] = code; @@ -264,7 +256,7 @@ } } } else { - for (i = this.start;index < length && i < 64; ++index) { + for (i = this.start; index < length && i < 64; ++index) { code = message.charCodeAt(index); if (code < 0x80) { blocks[i >> 2] |= code << SHIFT[i++ & 3]; @@ -632,7 +624,7 @@ }); } } -}(this)); +})(); @@ -649,7 +641,7 @@
- Documentation generated by JSDoc 3.4.0 on Thu Mar 31 2016 16:24:20 GMT+0800 (CST) + Documentation generated by JSDoc 3.4.3 on Wed Jan 18 2017 09:43:27 GMT+0800 (CST)
diff --git a/doc/styles/jsdoc-default.css b/doc/styles/jsdoc-default.css index 24aa20f..ede1919 100644 --- a/doc/styles/jsdoc-default.css +++ b/doc/styles/jsdoc-default.css @@ -153,7 +153,7 @@ h1 margin: 12px 24px 20px; } -h2, h3 +h2, h3.subsection-title { font-size: 30px; font-weight: 700; @@ -161,6 +161,13 @@ h2, h3 margin-bottom: 12px; } +h3 +{ + font-size: 24px; + letter-spacing: -0.5px; + margin-bottom: 12px; +} + h4 { font-size: 18px; @@ -185,6 +192,32 @@ h6 font-style: italic; } +table +{ + border-spacing: 0; + border: 0; + border-collapse: collapse; +} + +td, th +{ + border: 1px solid #ddd; + margin: 0px; + text-align: left; + vertical-align: top; + padding: 4px 6px; + display: table-cell; +} + +thead tr +{ + background-color: #ddd; + font-weight: bold; +} + +th { border-right: 1px solid #aaa; } +tr > th:last-child { border-right: 1px solid #ddd; } + .ancestors { color: #999; } .ancestors a { @@ -296,44 +329,12 @@ h6 user-select: text; } -.params, .props -{ - border-spacing: 0; - border: 0; - border-collapse: collapse; -} - .params .name, .props .name, .name code { color: #4D4E53; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 100%; } -.params td, .params th, .props td, .props th -{ - border: 1px solid #ddd; - margin: 0px; - text-align: left; - vertical-align: top; - padding: 4px 6px; - display: table-cell; -} - -.params thead tr, .props thead tr -{ - background-color: #ddd; - font-weight: bold; -} - -.params .params thead tr, .props .props thead tr -{ - background-color: #fff; - font-weight: bold; -} - -.params th, .props th { border-right: 1px solid #aaa; } -.params thead .last, .props thead .last { border-right: 1px solid #ddd; } - .params td.description > p:first-child, .props td.description > p:first-child { diff --git a/package.json b/package.json index f626599..a29b47d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-md5", - "version": "0.4.1", + "version": "0.4.2", "description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.", "main": "src/md5.js", "devDependencies": { diff --git a/src/md5.js b/src/md5.js index ecfb312..8f401a2 100644 --- a/src/md5.js +++ b/src/md5.js @@ -2,21 +2,22 @@ * [js-md5]{@link https://github.com/emn178/js-md5} * * @namespace md5 - * @version 0.4.1 + * @version 0.4.2 * @author Chen, Yi-Cyuan [emn178@gmail.com] - * @copyright Chen, Yi-Cyuan 2014-2016 + * @copyright Chen, Yi-Cyuan 2014-2017 * @license MIT */ -(function (root) { +(function () { 'use strict'; - var NODE_JS = typeof process == 'object' && process.versions && process.versions.node; + var root = typeof window === 'object' ? window : {}; + var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node; if (NODE_JS) { root = global; } - var COMMON_JS = !root.JS_MD5_TEST && typeof module == 'object' && module.exports; - var AMD = typeof define == 'function' && define.amd; - var ARRAY_BUFFER = !root.JS_MD5_TEST && typeof ArrayBuffer != 'undefined'; + var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && typeof module === 'object' && module.exports; + var AMD = typeof define === 'function' && define.amd; + var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined'; var HEX_CHARS = '0123456789abcdef'.split(''); var EXTRA = [128, 32768, 8388608, -2147483648]; var SHIFT = [0, 8, 16, 24]; @@ -114,7 +115,7 @@ method.update = function (message) { return method.create().update(message); }; - for (var i = 0;i < OUTPUT_TYPES.length;++i) { + for (var i = 0; i < OUTPUT_TYPES.length; ++i) { var type = OUTPUT_TYPES[i]; method[type] = createOutputMethod(type); } @@ -122,21 +123,12 @@ }; var nodeWrap = function (method) { - var crypto, Buffer; - try { - if (root.JS_MD5_TEST) { - throw 'JS_MD5_TEST'; - } - crypto = require('crypto'); - Buffer = require('buffer').Buffer; - } catch (e) { - console.log(e); - return method; - } + var crypto = require('crypto'); + var Buffer = require('buffer').Buffer; var nodeMethod = function (message) { - if (typeof message == 'string') { + if (typeof message === 'string') { return crypto.createHash('md5').update(message, 'utf8').digest('hex'); - } else if (message.constructor == ArrayBuffer) { + } else if (message.constructor === ArrayBuffer) { message = new Uint8Array(message); } else if (message.length === undefined) { return method(message); @@ -206,17 +198,17 @@ if (notString) { if (ARRAY_BUFFER) { - for (i = this.start;index < length && i < 64; ++index) { + for (i = this.start; index < length && i < 64; ++index) { buffer8[i++] = message[index]; } } else { - for (i = this.start;index < length && i < 64; ++index) { + for (i = this.start; index < length && i < 64; ++index) { blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; } } } else { if (ARRAY_BUFFER) { - for (i = this.start;index < length && i < 64; ++index) { + for (i = this.start; index < length && i < 64; ++index) { code = message.charCodeAt(index); if (code < 0x80) { buffer8[i++] = code; @@ -236,7 +228,7 @@ } } } else { - for (i = this.start;index < length && i < 64; ++index) { + for (i = this.start; index < length && i < 64; ++index) { code = message.charCodeAt(index); if (code < 0x80) { blocks[i >> 2] |= code << SHIFT[i++ & 3]; @@ -604,4 +596,4 @@ }); } } -}(this)); +})(); diff --git a/tests/node-test.js b/tests/node-test.js index fef2577..ee64c2e 100644 --- a/tests/node-test.js +++ b/tests/node-test.js @@ -1,12 +1,38 @@ -md5 = require('../src/md5.js'); +// Node.js env expect = require('expect.js'); +md5 = require('../src/md5.js'); require('./test.js'); delete require.cache[require.resolve('../src/md5.js')] delete require.cache[require.resolve('./test.js')] md5 = null -JS_MD5_TEST = true; +// Webpack browser env +JS_MD5_NO_NODE_JS = true; +window = global; +md5 = require('../src/md5.js'); +require('./test.js'); + +delete require.cache[require.resolve('../src/md5.js')]; +delete require.cache[require.resolve('./test.js')]; +md5 = null; + +// browser env +JS_MD5_NO_NODE_JS = true; +JS_MD5_NO_COMMON_JS = true; +window = global; +require('../src/md5.js'); +require('./test.js'); + +delete require.cache[require.resolve('../src/md5.js')]; +delete require.cache[require.resolve('./test.js')]; +md5 = null; + +// browser env and no array buffer +JS_MD5_NO_NODE_JS = true; +JS_MD5_NO_COMMON_JS = true; +JS_MD5_NO_ARRAY_BUFFER = true; +window = global; require('../src/md5.js'); require('./test.js'); @@ -14,6 +40,11 @@ delete require.cache[require.resolve('../src/md5.js')]; delete require.cache[require.resolve('./test.js')]; md5 = null; +// browser AMD +JS_MD5_NO_NODE_JS = true; +JS_MD5_NO_COMMON_JS = true; +JS_MD5_NO_ARRAY_BUFFER = false; +window = global; define = function (func) { md5 = func(); require('./test.js'); diff --git a/tests/test.js b/tests/test.js index 503aae8..7454ff1 100644 --- a/tests/test.js +++ b/tests/test.js @@ -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; }