11 Commits
Author SHA1 Message Date
Yi-Cyuan Chen 0263ab835f Fixed incorrect result when first bit is 1 of bytes. #18 2017-12-18 18:50:24 +08:00
Yi-Cyuan Chen 5f0bd5a888 Improved performance of hBytes increment. 2017-10-31 20:30:01 +08:00
Yi-Cyuan Chen cb8eb73ef1 Fixed incorrect result when file size >= 4G. 2017-10-29 21:22:00 +08:00
Yi-Cyuan Chen 24d8eb504d Fixed incorrect result when file size >= 512M. 2017-10-29 20:17:07 +08:00
Yi-Cyuan Chen a54f102b8a * Fixed ArrayBuffer.isView issue in IE10.
* Improved performance of input check.
2017-10-07 10:12:06 +08:00
Chen Yi-Cyuan e7f1ca7da8 fixed unit tests 2017-10-03 09:40:36 +08:00
Chen Yi-Cyuan b808ed4605 Added support base64 string output. 2017-07-28 14:12:37 +08:00
Chen, Yi-Cyuan 2bdc4894fc fixed travis build 2017-07-14 13:28:43 +08:00
Chen, Yi-Cyuan c00df3af37 Added
- support for web worker. #11

Changed
- throw error if input type is incorrect.
- prevent webpack to require dependencies.
2017-07-14 13:10:27 +08:00
Chen, Yi-Cyuan 8b9a23ce32 Fixed root is undefined in some special environment. #7 2017-01-18 09:44:08 +08:00
Chen Yi-Cyuan da009f933f update comment version 2016-07-30 20:39:20 +08:00
23 changed files with 3020 additions and 271 deletions
-2
View File
@@ -1,2 +0,0 @@
/tests/
node_modules/
+2 -2
View File
@@ -1,2 +1,2 @@
covreporter
node_modules
/node_modules/
/covreporter/
+9
View File
@@ -0,0 +1,9 @@
/node_modules/
/coverage/
/.nyc_output/
/tests/
/doc/
.covignore
.travis.yml
.npmignore
bower.json
+3 -7
View File
@@ -1,14 +1,10 @@
language: node_js
node_js:
- "4.1"
- "4.0"
- "0.12"
- "0.11"
- "0.10"
- "6.11.4"
- "8.6.0"
before_install:
- npm install coveralls
- npm install mocha-lcov-reporter
script: npm run-script coveralls
after_success: npm run coveralls
branches:
only:
- master
+80 -33
View File
@@ -1,54 +1,101 @@
# v0.4.1 / 2016-03-31
# Change Log
* Removed length detection in node.js.
* Deprecated `buffer` and replace by `arrayBuffer`.
## v0.7.3 / 2017-12-18
### Fixed
- incorrect result when first bit is 1 of bytes. #18
# v0.4.0 / 2015-12-28
## v0.7.2 / 2017-10-31
### Improved
- performance of hBytes increment.
* Added support for update hash.
* Added support for bytes array output.
* Added support for ArrayBuffer output.
* Added support for AMD.
## v0.7.1 / 2017-10-29
### Fixed
- incorrect result when file size >= 4G.
# v0.3.0 / 2015-03-07
## v0.7.0 / 2017-10-29
### Fixed
- incorrect result when file size >= 512M.
* Support byte Array, Uint8Array and ArrayBuffer input.
## v0.6.1 / 2017-10-07
### Fixed
- ArrayBuffer.isView issue in IE10.
# v0.2.2 / 2015-02-01
### Improved
- performance of input check.
* Fixed bug when special length.
* Improve performance for node.js.
## v0.6.0 / 2017-07-28
### Added
- support base64 string output.
# v0.2.1 / 2015-01-13
## v0.5.0 / 2017-07-14
### Added
- support for web worker. #11
* Improve performance.
### Changed
- throw error if input type is incorrect.
- prevent webpack to require dependencies.
# v0.2.0 / 2015-01-12
## v0.4.2 / 2017-01-18
### Fixed
- `root` is undefined in some special environment. #7
* Remove ascii parameter.
* Improve performance.
## v0.4.1 / 2016-03-31
### Removed
- length detection in node.js.
### Deprecated
- `buffer` and replace by `arrayBuffer`.
# v0.1.4 / 2015-01-11
## v0.4.0 / 2015-12-28
### Added
- support for update hash.
- support for bytes array output.
- support for ArrayBuffer output.
- support for AMD.
* Improve performance.
* Add test case.
## v0.3.0 / 2015-03-07
### Added
- support byte Array, Uint8Array and ArrayBuffer input.
# v0.1.3 / 2015-01-05
## v0.2.2 / 2015-02-01
### Fixed
- bug when special length.
### Improve
- performance for node.js.
* Improve performance.
* Add bower package.
* Fixed JSHint warnings.
* Add travis.
* Add coveralls.
## v0.2.1 / 2015-01-13
### Improve
- performance.
# v0.1.2 / 2014-07-27
## v0.2.0 / 2015-01-12
### Removed
- ascii parameter.
### Improve
- performance.
Fixed accents bug
## v0.1.4 / 2015-01-11
### Improve
- performance.
### Added
- test cases.
# v0.1.1 / 2014-01-05
## v0.1.3 / 2015-01-05
### Added
- bower package.
- travis.
- coveralls.
### Improved
- performance.
### Fixed
- JSHint warnings.
Update license
## v0.1.2 / 2014-07-27
### Fixed
- accents bug
# v0.1.0 / 2014-01-04
## v0.1.1 / 2014-01-05
### Changed
- license
Initial release
## v0.1.0 / 2014-01-04
### Added
- initial release
+1 -1
View File
@@ -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
+1 -4
View File
@@ -65,12 +65,9 @@ md5.array(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248
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.
md5.base64(''); // 1B2M2Y8AsgTpgAmY7PhCfg==
```
## 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).
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "js-md5",
"version": "0.4.1",
"version": "0.7.3",
"main": ["src/md5.js"],
"ignore": [
"tests"
+3 -3
View File
File diff suppressed because one or more lines are too long
+164 -10
View File
@@ -28,7 +28,7 @@
<header>
<h2>Md5</h2>
<h2><span class="attribs"><span class="type-signature"></span></span>Md5<span class="signature">()</span><span class="type-signature"></span></h2>
</header>
@@ -40,12 +40,14 @@
<h4 class="name" id="Md5"><span class="type-signature"></span>new Md5<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
This is internal class.
</div>
@@ -91,7 +93,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line149">line 149</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line178">line 178</a>
</li></ul></dd>
@@ -125,6 +127,8 @@
</div>
@@ -140,6 +144,8 @@
<h3 class="subsection-title">Methods</h3>
@@ -147,12 +153,14 @@
<h4 class="name" id="array"><span class="type-signature"></span>array<span class="signature">()</span><span class="type-signature"> &rarr; {Array}</span></h4>
<div class="description">
Output hash as bytes array
</div>
@@ -198,7 +206,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line531">line 531</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line579">line 579</a>
</li></ul></dd>
@@ -252,6 +260,8 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.array();</code></pre>
@@ -263,12 +273,14 @@
<h4 class="name" id="arrayBuffer"><span class="type-signature"></span>arrayBuffer<span class="signature">()</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
<div class="description">
Output hash as ArrayBuffer
</div>
@@ -314,7 +326,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line543">line 543</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line591">line 591</a>
</li></ul></dd>
@@ -368,6 +380,8 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.arrayBuffer();</code></pre>
@@ -379,12 +393,134 @@
<h4 class="name" id="base64"><span class="type-signature"></span>base64<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
<div class="description">
Output hash as base64 string
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line626">line 626</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5.html#.base64">md5.base64</a></li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
base64 string
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>hash.base64();</code></pre>
<h4 class="name" id="buffer"><span class="type-signature"></span>buffer<span class="signature">()</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
<div class="description">
Output hash as ArrayBuffer
</div>
@@ -432,7 +568,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line565">line 565</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line613">line 613</a>
</li></ul></dd>
@@ -486,6 +622,8 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.buffer();</code></pre>
@@ -497,12 +635,14 @@
<h4 class="name" id="digest"><span class="type-signature"></span>digest<span class="signature">()</span><span class="type-signature"> &rarr; {Array}</span></h4>
<div class="description">
Output hash as bytes array
</div>
@@ -548,7 +688,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line509">line 509</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line557">line 557</a>
</li></ul></dd>
@@ -602,6 +742,8 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.digest();</code></pre>
@@ -613,12 +755,14 @@
<h4 class="name" id="hex"><span class="type-signature"></span>hex<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
<div class="description">
Output hash as hex string
</div>
@@ -664,7 +808,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line464">line 464</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line512">line 512</a>
</li></ul></dd>
@@ -718,6 +862,8 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.hex();</code></pre>
@@ -729,12 +875,14 @@
<h4 class="name" id="toString"><span class="type-signature"></span>toString<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
<div class="description">
Output hash as hex string
</div>
@@ -780,7 +928,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line497">line 497</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line545">line 545</a>
</li></ul></dd>
@@ -834,6 +982,8 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.toString();</code></pre>
@@ -845,12 +995,14 @@
<h4 class="name" id="update"><span class="type-signature"></span>update<span class="signature">(message)</span><span class="type-signature"> &rarr; {<a href="Md5_.html">Md5</a>}</span></h4>
<div class="description">
Update hash
</div>
@@ -954,7 +1106,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line177">line 177</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line206">line 206</a>
</li></ul></dd>
@@ -1015,6 +1167,8 @@
</article>
</section>
@@ -1031,7 +1185,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Mar 31 2016 16:24:21 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Dec 18 2017 18:48:59 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>
+18 -3
View File
@@ -94,6 +94,8 @@
<h3 class="subsection-title">Methods</h3>
@@ -101,12 +103,14 @@
<h4 class="name" id="md5%08"><span class="type-signature"></span>md5<span class="signature">(message)</span><span class="type-signature"> &rarr; {String}</span></h4>
<div class="description">
Md5 hash function, export to global in browsers.
</div>
@@ -210,7 +214,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line583">line 583</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line659">line 659</a>
</li></ul></dd>
@@ -257,9 +261,20 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5(''); // d41d8cd98f00b204e9800998ecf8427e
<pre class="prettyprint"><code>md5(''); // d41d8cd98f00b204e9800998ecf8427e
md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6
md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
// It also supports UTF-8 encoding
md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
md5([]); // d41d8cd98f00b204e9800998ecf8427e
md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e</code></pre>
@@ -285,7 +300,7 @@
<br class="clear">
<footer>
</div>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Dec 18 2017 18:48:59 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>
+3 -3
View File
@@ -77,8 +77,8 @@ 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.</code></pre><h2>Benchmark</h2><p><a href="http://jsperf.com/md5-shootout/81">UTF8</a><br><a href="http://jsperf.com/md5-shootout/82">ASCII</a></p>
<h2>License</h2><p>The project is released under the <a href="http://www.opensource.org/licenses/MIT">MIT license</a>.</p>
md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
md5.base64(''); // 1B2M2Y8AsgTpgAmY7PhCfg==</code></pre><h2>License</h2><p>The project is released under the <a href="http://www.opensource.org/licenses/MIT">MIT license</a>.</p>
<h2>Contact</h2><p>The project's website is located at https://github.com/emn178/js-md5<br>Author: Chen, Yi-Cyuan (emn178@gmail.com)</p></article>
</section>
@@ -96,7 +96,7 @@ md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in no
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Mar 31 2016 16:24:21 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Dec 18 2017 18:48:59 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>
+218 -12
View File
@@ -47,7 +47,7 @@
<dt class="tag-version">Version:</dt>
<dd class="tag-version"><ul class="dummy"><li>0.4.0</li></ul></dd>
<dd class="tag-version"><ul class="dummy"><li>0.7.3</li></ul></dd>
@@ -75,7 +75,7 @@
<dt class="tag-copyright">Copyright:</dt>
<dd class="tag-copyright"><ul class="dummy"><li>Chen, Yi-Cyuan 2014-2016</li></ul></dd>
<dd class="tag-copyright"><ul class="dummy"><li>Chen, Yi-Cyuan 2014-2017</li></ul></dd>
@@ -117,6 +117,8 @@
<h3 class="subsection-title">Methods</h3>
@@ -124,12 +126,14 @@
<h4 class="name" id=".array"><span class="type-signature">(static) </span>array<span class="signature">(message)</span><span class="type-signature"> &rarr; {Array}</span></h4>
<div class="description">
Output hash as bytes array
</div>
@@ -233,7 +237,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line52">line 52</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line74">line 74</a>
</li></ul></dd>
@@ -280,6 +284,8 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5.array('The quick brown fox jumps over the lazy dog');</code></pre>
@@ -291,12 +297,14 @@
<h4 class="name" id=".arrayBuffer"><span class="type-signature">(static) </span>arrayBuffer<span class="signature">(message)</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
<div class="description">
Output hash as ArrayBuffer
</div>
@@ -400,7 +408,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line61">line 61</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line83">line 83</a>
</li></ul></dd>
@@ -447,6 +455,8 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5.arrayBuffer('The quick brown fox jumps over the lazy dog');</code></pre>
@@ -458,12 +468,185 @@
<h4 class="name" id=".base64"><span class="type-signature">(static) </span>base64<span class="signature">(message)</span><span class="type-signature"> &rarr; {String}</span></h4>
<div class="description">
Output hash as base64 string
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line102">line 102</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
base64 string
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>md5.base64('The quick brown fox jumps over the lazy dog');</code></pre>
<h4 class="name" id=".buffer"><span class="type-signature">(static) </span>buffer<span class="signature">(message)</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
<div class="description">
Output hash as ArrayBuffer
</div>
@@ -569,7 +752,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line70">line 70</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line92">line 92</a>
</li></ul></dd>
@@ -616,6 +799,8 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5.buffer('The quick brown fox jumps over the lazy dog');</code></pre>
@@ -627,12 +812,14 @@
<h4 class="name" id=".create"><span class="type-signature">(static) </span>create<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="Md5_.html">Md5</a>}</span></h4>
<div class="description">
Create Md5 object
</div>
@@ -678,7 +865,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line86">line 86</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line117">line 117</a>
</li></ul></dd>
@@ -725,6 +912,8 @@
<h5>Example</h5>
<pre class="prettyprint"><code>var hash = md5.create();</code></pre>
@@ -736,12 +925,14 @@
<h4 class="name" id=".digest"><span class="type-signature">(static) </span>digest<span class="signature">(message)</span><span class="type-signature"> &rarr; {Array}</span></h4>
<div class="description">
Output hash as bytes array
</div>
@@ -845,7 +1036,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line43">line 43</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line65">line 65</a>
</li></ul></dd>
@@ -892,6 +1083,8 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5.digest('The quick brown fox jumps over the lazy dog');</code></pre>
@@ -903,12 +1096,14 @@
<h4 class="name" id=".hex"><span class="type-signature">(static) </span>hex<span class="signature">(message)</span><span class="type-signature"> &rarr; {String}</span></h4>
<div class="description">
Output hash as hex string
</div>
@@ -1012,7 +1207,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line32">line 32</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line54">line 54</a>
</li></ul></dd>
@@ -1059,9 +1254,14 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5.hex('The quick brown fox jumps over the lazy dog');
<pre class="prettyprint"><code>md5.hex('The quick brown fox jumps over the lazy dog');
// equal to
md5('The quick brown fox jumps over the lazy dog');</code></pre>
@@ -1076,6 +1276,7 @@
<div class="description">
Create and update Md5 object
</div>
@@ -1179,7 +1380,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<dt class="tag-source">Source:</dt>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line125">line 125</a>
</li></ul></dd>
@@ -1226,9 +1427,14 @@
<h5>Example</h5>
<h5>Example</h5>
<pre class="prettyprint"><code>var hash = md5.update('The quick brown fox jumps over the lazy dog');
// equal to
var hash = md5.create();
hash.update('The quick brown fox jumps over the lazy dog');</code></pre>
@@ -1254,7 +1460,7 @@
<br class="clear">
<footer>
</nav>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Dec 18 2017 18:48:59 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>
+105 -29
View File
@@ -30,25 +30,35 @@
* [js-md5]{@link https://github.com/emn178/js-md5}
*
* @namespace md5
* @version 0.4.0
* @version 0.7.3
* @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' &amp;&amp; process.versions &amp;&amp; process.versions.node;
var ERROR = 'input is invalid type';
var WINDOW = typeof window === 'object';
var root = WINDOW ? window : {};
if (root.JS_MD5_NO_WINDOW) {
WINDOW = false;
}
var WEB_WORKER = !WINDOW &amp;&amp; typeof self === 'object';
var NODE_JS = !root.JS_MD5_NO_NODE_JS &amp;&amp; typeof process === 'object' &amp;&amp; process.versions &amp;&amp; process.versions.node;
if (NODE_JS) {
root = global;
} else if (WEB_WORKER) {
root = self;
}
var COMMON_JS = !root.JS_MD5_TEST &amp;&amp; typeof module == 'object' &amp;&amp; module.exports;
var AMD = typeof define == 'function' &amp;&amp; define.amd;
var ARRAY_BUFFER = !root.JS_MD5_TEST &amp;&amp; typeof ArrayBuffer != 'undefined';
var COMMON_JS = !root.JS_MD5_NO_COMMON_JS &amp;&amp; typeof module === 'object' &amp;&amp; module.exports;
var AMD = typeof define === 'function' &amp;&amp; define.amd;
var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER &amp;&amp; typeof ArrayBuffer !== 'undefined';
var HEX_CHARS = '0123456789abcdef'.split('');
var EXTRA = [128, 32768, 8388608, -2147483648];
var SHIFT = [0, 8, 16, 24];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer'];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer', 'base64'];
var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
var blocks = [], buffer8;
if (ARRAY_BUFFER) {
@@ -57,6 +67,18 @@
blocks = new Uint32Array(buffer);
}
if (root.JS_MD5_NO_NODE_JS || !Array.isArray) {
Array.isArray = function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
}
if (ARRAY_BUFFER &amp;&amp; (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
ArrayBuffer.isView = function (obj) {
return typeof obj === 'object' &amp;&amp; obj.buffer &amp;&amp; obj.buffer.constructor === ArrayBuffer;
};
}
/**
* @method hex
* @memberof md5
@@ -105,6 +127,15 @@
* @example
* md5.buffer('The quick brown fox jumps over the lazy dog');
*/
/**
* @method base64
* @memberof md5
* @description Output hash as base64 string
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {String} base64 string
* @example
* md5.base64('The quick brown fox jumps over the lazy dog');
*/
var createOutputMethod = function (outputType) {
return function (message) {
return new Md5(true).update(message)[outputType]();
@@ -150,26 +181,24 @@
};
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 = eval("require('crypto')");
var Buffer = eval("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 === null || message === undefined) {
throw ERROR;
} else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (message.length === undefined) {
}
}
if (Array.isArray(message) || ArrayBuffer.isView(message) ||
message.constructor === Buffer) {
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
} else {
return method(message);
}
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
};
return nodeMethod;
};
@@ -197,7 +226,7 @@
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.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0;
this.finalized = this.hashed = false;
this.first = true;
}
@@ -215,11 +244,25 @@
if (this.finalized) {
return;
}
var notString = typeof(message) != 'string';
if (notString &amp;&amp; message.constructor == root.ArrayBuffer) {
var notString, type = typeof message;
if (type !== 'string') {
if (type === 'object') {
if (message === null) {
throw ERROR;
} else if (ARRAY_BUFFER &amp;&amp; message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (!Array.isArray(message)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
throw ERROR;
}
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
}
} else {
throw ERROR;
}
notString = true;
}
var code, index = 0, i, length = message.length, blocks = this.blocks;
var buffer8 = this.buffer8;
while (index &lt; length) {
@@ -295,6 +338,10 @@
this.start = i;
}
}
if (this.bytes > 4294967295) {
this.hBytes += this.bytes / 4294967296 &lt;&lt; 0;
this.bytes = this.bytes % 4294967296;
}
return this;
};
@@ -316,6 +363,7 @@
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
blocks[14] = this.bytes &lt;&lt; 3;
blocks[15] = this.hBytes &lt;&lt; 3 | this.bytes >>> 29;
this.hash();
};
@@ -603,6 +651,34 @@
*/
Md5.prototype.buffer = Md5.prototype.arrayBuffer;
/**
* @method base64
* @memberof Md5
* @instance
* @description Output hash as base64 string
* @returns {String} base64 string
* @see {@link md5.base64}
* @example
* hash.base64();
*/
Md5.prototype.base64 = function () {
var v1, v2, v3, base64Str = '', bytes = this.array();
for (var i = 0; i &lt; 15;) {
v1 = bytes[i++];
v2 = bytes[i++];
v3 = bytes[i++];
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
BASE64_ENCODE_CHAR[(v1 &lt;&lt; 4 | v2 >>> 4) &amp; 63] +
BASE64_ENCODE_CHAR[(v2 &lt;&lt; 2 | v3 >>> 6) &amp; 63] +
BASE64_ENCODE_CHAR[v3 &amp; 63];
}
v1 = bytes[i];
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
BASE64_ENCODE_CHAR[(v1 &lt;&lt; 4) &amp; 63] +
'==';
return base64Str;
};
var exports = createMethod();
if (COMMON_JS) {
@@ -632,7 +708,7 @@
});
}
}
}(this));
})();
</code></pre>
</article>
</section>
@@ -649,7 +725,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Mar 31 2016 16:24:20 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Dec 18 2017 18:48:59 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>
+40 -35
View File
@@ -78,6 +78,10 @@ article dl {
margin-bottom: 40px;
}
article img {
max-width: 100%;
}
section
{
display: block;
@@ -153,7 +157,7 @@ h1
margin: 12px 24px 20px;
}
h2, h3
h2, h3.subsection-title
{
font-size: 30px;
font-weight: 700;
@@ -161,6 +165,13 @@ h2, h3
margin-bottom: 12px;
}
h3
{
font-size: 24px;
letter-spacing: -0.5px;
margin-bottom: 12px;
}
h4
{
font-size: 18px;
@@ -185,8 +196,34 @@ h6
font-style: italic;
}
.ancestors { color: #999; }
.ancestors a
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, .attribs { color: #999; }
.ancestors a, .attribs a
{
color: #999 !important;
text-decoration: none;
@@ -296,44 +333,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
{
+1954
View File
File diff suppressed because it is too large Load Diff
+13 -7
View File
@@ -1,22 +1,23 @@
{
"name": "js-md5",
"version": "0.4.1",
"version": "0.7.3",
"description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.",
"main": "src/md5.js",
"devDependencies": {
"expect.js": "~0.3.1",
"jscoverage": "~0.5.9",
"jsdoc": "^3.4.0",
"mocha": "~2.3.4",
"nyc": "^11.3.0",
"requirejs": "^2.1.22",
"uglifyjs": "~2.4.10"
"uglify-js": "^3.1.9",
"webworker-threads": "^0.7.11"
},
"scripts": {
"test": "mocha tests/node-test.js -r jscoverage",
"report": "mocha tests/node-test.js -r jscoverage --covout=html",
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls",
"test": "nyc mocha tests/node-test.js",
"report": "nyc --reporter=html --reporter=text mocha tests/node-test.js",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"doc": "rm -rf doc;jsdoc src README.md -d doc",
"compress": "uglifyjs src/md5.js --compress --mangle --comments --output build/md5.min.js",
"compress": "uglifyjs src/md5.js -c -m eval --comments --output build/md5.min.js",
"build": "npm run-script compress;npm run-script doc"
},
"repository": {
@@ -35,5 +36,10 @@
"homepage": "https://github.com/emn178/js-md5",
"bugs": {
"url": "https://github.com/emn178/js-md5/issues"
},
"nyc": {
"exclude": [
"tests"
]
}
}
+104 -28
View File
@@ -2,25 +2,35 @@
* [js-md5]{@link https://github.com/emn178/js-md5}
*
* @namespace md5
* @version 0.4.0
* @version 0.7.3
* @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 ERROR = 'input is invalid type';
var WINDOW = typeof window === 'object';
var root = WINDOW ? window : {};
if (root.JS_MD5_NO_WINDOW) {
WINDOW = false;
}
var WEB_WORKER = !WINDOW && typeof self === 'object';
var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
} else if (WEB_WORKER) {
root = self;
}
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];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer'];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer', 'base64'];
var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
var blocks = [], buffer8;
if (ARRAY_BUFFER) {
@@ -29,6 +39,18 @@
blocks = new Uint32Array(buffer);
}
if (root.JS_MD5_NO_NODE_JS || !Array.isArray) {
Array.isArray = function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
}
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
ArrayBuffer.isView = function (obj) {
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
};
}
/**
* @method hex
* @memberof md5
@@ -77,6 +99,15 @@
* @example
* md5.buffer('The quick brown fox jumps over the lazy dog');
*/
/**
* @method base64
* @memberof md5
* @description Output hash as base64 string
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {String} base64 string
* @example
* md5.base64('The quick brown fox jumps over the lazy dog');
*/
var createOutputMethod = function (outputType) {
return function (message) {
return new Md5(true).update(message)[outputType]();
@@ -122,26 +153,24 @@
};
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 = eval("require('crypto')");
var Buffer = eval("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 === null || message === undefined) {
throw ERROR;
} else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (message.length === undefined) {
}
}
if (Array.isArray(message) || ArrayBuffer.isView(message) ||
message.constructor === Buffer) {
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
} else {
return method(message);
}
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
};
return nodeMethod;
};
@@ -169,7 +198,7 @@
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.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0;
this.finalized = this.hashed = false;
this.first = true;
}
@@ -187,11 +216,25 @@
if (this.finalized) {
return;
}
var notString = typeof(message) != 'string';
if (notString && message.constructor == root.ArrayBuffer) {
var notString, type = typeof message;
if (type !== 'string') {
if (type === 'object') {
if (message === null) {
throw ERROR;
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (!Array.isArray(message)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
throw ERROR;
}
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
}
} else {
throw ERROR;
}
notString = true;
}
var code, index = 0, i, length = message.length, blocks = this.blocks;
var buffer8 = this.buffer8;
while (index < length) {
@@ -267,6 +310,10 @@
this.start = i;
}
}
if (this.bytes > 4294967295) {
this.hBytes += this.bytes / 4294967296 << 0;
this.bytes = this.bytes % 4294967296;
}
return this;
};
@@ -288,6 +335,7 @@
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
blocks[14] = this.bytes << 3;
blocks[15] = this.hBytes << 3 | this.bytes >>> 29;
this.hash();
};
@@ -575,6 +623,34 @@
*/
Md5.prototype.buffer = Md5.prototype.arrayBuffer;
/**
* @method base64
* @memberof Md5
* @instance
* @description Output hash as base64 string
* @returns {String} base64 string
* @see {@link md5.base64}
* @example
* hash.base64();
*/
Md5.prototype.base64 = function () {
var v1, v2, v3, base64Str = '', bytes = this.array();
for (var i = 0; i < 15;) {
v1 = bytes[i++];
v2 = bytes[i++];
v3 = bytes[i++];
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] +
BASE64_ENCODE_CHAR[v3 & 63];
}
v1 = bytes[i];
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
BASE64_ENCODE_CHAR[(v1 << 4) & 63] +
'==';
return base64Str;
};
var exports = createMethod();
if (COMMON_JS) {
@@ -604,4 +680,4 @@
});
}
}
}(this));
})();
+87 -10
View File
@@ -1,19 +1,61 @@
md5 = require('../src/md5.js');
expect = require('expect.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;
require('../src/md5.js');
require('./test.js');
Worker = require('webworker-threads').Worker;
function unset() {
delete require.cache[require.resolve('../src/md5.js')];
delete require.cache[require.resolve('./test.js')];
md5 = null;
BUFFER = undefined;
JS_MD5_NO_WINDOW = undefined;
JS_MD5_NO_NODE_JS = undefined;
JS_MD5_NO_COMMON_JS = undefined;
JS_MD5_NO_ARRAY_BUFFER = undefined;
JS_MD5_NO_ARRAY_BUFFER_IS_VIEW = undefined;
window = undefined;
}
function runCommonJsTest() {
md5 = require('../src/md5.js');
require('./test.js');
unset();
}
function runWindowTest() {
window = global;
require('../src/md5.js');
require('./test.js');
unset();
}
// Node.js env
BUFFER = true;
runCommonJsTest();
// Webpack browser env
JS_MD5_NO_NODE_JS = true;
runCommonJsTest();
// browser env
JS_MD5_NO_NODE_JS = true;
JS_MD5_NO_COMMON_JS = true;
runWindowTest();
// browser env and no array buffer
JS_MD5_NO_NODE_JS = true;
JS_MD5_NO_COMMON_JS = true;
JS_MD5_NO_ARRAY_BUFFER = true;
runWindowTest();
// browser env and no isView
JS_MD5_NO_NODE_JS = true;
JS_MD5_NO_COMMON_JS = true;
JS_MD5_NO_ARRAY_BUFFER_IS_VIEW = true;
runWindowTest();
// browser AMD
JS_MD5_NO_NODE_JS = true;
JS_MD5_NO_COMMON_JS = true;
window = global;
define = function (func) {
md5 = func();
require('./test.js');
@@ -21,3 +63,38 @@ define = function (func) {
define.amd = true;
require('../src/md5.js');
unset();
// webworker
WORKER = 'tests/worker.js';
SOURCE = 'src/md5.js';
require('./worker-test.js');
delete require.cache[require.resolve('./worker-test.js')];
// cover webworker
JS_MD5_NO_WINDOW = true;
JS_MD5_NO_NODE_JS = true;
WORKER = './worker.js';
SOURCE = '../src/md5.js';
window = global;
self = global;
Worker = function (file) {
require(file);
currentWorker = this;
this.postMessage = function (data) {
onmessage({data: data});
};
}
postMessage = function (data) {
currentWorker.onmessage({data: data});
}
importScripts = function () {};
md5 = require('../src/md5.js');
require('./worker-test.js');
+89 -15
View File
@@ -42,29 +42,67 @@
'd41d8cd98f00b204e9800998ecf8427e': [],
'93b885adfe0da089cdf634904fd59f71': [0],
'9e107d9d372bb6826bd81d3542a419d6': [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]
},
'Uint8Array': {
'9e107d9d372bb6826bd81d3542a419d6': 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])
},
'Int8Array': {
'9e107d9d372bb6826bd81d3542a419d6': new Int8Array([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])
},
'ArrayBuffer': {
'93b885adfe0da089cdf634904fd59f71': new ArrayBuffer(1)
},
'Object': {
'd41d8cd98f00b204e9800998ecf8427e': {},
'd41d8cd98f00b204e9800998ecf8427e': {what: 'ever'}
}
};
if (typeof process == 'object') {
var base64TestCases = {
'ascii': {
'1B2M2Y8AsgTpgAmY7PhCfg==': '',
'nhB9nTcrtoJr2B01QqQZ1g==': 'The quick brown fox jumps over the lazy dog',
'5NkJwpDQ+xygaP+t3yLL0A==': 'The quick brown fox jumps over the lazy dog.'
},
'ascii more than 64 bytes': {
'9jhy73vJeoqOrbpvCIHeUw==': 'The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.'
},
'UTF8': {
'p7rCI5/NyzoGeQPYB3xKBw==': '中文',
'7D7b87BaRJ/CBqATjHOcOw==': 'aécio',
'uQhpqvEhIQ9sVjlz+oVWUA==': '𠜎'
},
'UTF8 more than 64 bytes': {
'7c5hWxeebim+IxRbd+u9YQ==': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一',
'rTbJq2aaC6nORtPOkTTeNA==': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。'
},
'special length': {
'oRneY+SyOYQn2gbdeAJjsw==': '0123456780123456780123456780123456780123456780123456780',
'3a/YTr5jrrxGJrA3pWnXiw==': '01234567801234567801234567801234567801234567801234567801',
'nqBNdDYYeXzkZERbV4WmMA==': '0123456780123456780123456780123456780123456780123456780123456780',
'ZY2RSuQsSTiHSy54bM2keQ==': '01234567801234567801234567801234567801234567801234567801234567801234567',
'oIOjcQ1oV5Px8XmIv+PBdQ==': '012345678012345678012345678012345678012345678012345678012345678012345678',
'KyGoQ8/DHIAmoNg1vJG8mA==': '012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678',
'0C696XkmTHnhQVWfyfa2XA==': '012345678901234567',
'HO2BGvR+rTdIcvzKnXPdcQ==': '012345678901234567890123456789012345678901234567890123456789',
'/7gaJDpg2sRZKTAIc+BShw==': '012345678901234567中文',
},
'Array': {
'1B2M2Y8AsgTpgAmY7PhCfg==': [],
'k7iFrf4NoInN9jSQT9WfcQ==': [0],
'nhB9nTcrtoJr2B01QqQZ1g==': [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]
}
};
if (!(typeof JS_MD5_NO_ARRAY_BUFFER === 'boolean' && JS_MD5_NO_ARRAY_BUFFER)) {
testCases['Uint8Array'] = {
'9e107d9d372bb6826bd81d3542a419d6': 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])
};
testCases['Int8Array'] = {
'9e107d9d372bb6826bd81d3542a419d6': new Int8Array([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])
};
testCases['ArrayBuffer'] = {
'93b885adfe0da089cdf634904fd59f71': new ArrayBuffer(1)
};
}
if (typeof BUFFER === 'boolean' && BUFFER) {
testCases['Buffer'] = {
'd41d8cd98f00b204e9800998ecf8427e': new Buffer(0),
'9e107d9d372bb6826bd81d3542a419d6': 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 errorTestCases = [null, undefined, { length: 0 }, 0, 1, false, true, NaN, Infinity, function () {}];
var methods = [
{
name: 'md5',
@@ -154,6 +192,7 @@
}
];
describe('md5', function () {
methods.forEach(function (method) {
describe('#' + method.name, function () {
for (var testCaseName in testCases) {
@@ -173,7 +212,6 @@
});
});
describe('Md5', function () {
classMethods.forEach(function (method) {
describe('#' + method.name, function () {
for (var testCaseName in testCases) {
@@ -192,5 +230,41 @@
}
});
});
describe('#md5', function () {
errorTestCases.forEach(function (testCase) {
context('when ' + testCase, function () {
it('should throw error', function () {
expect(function () {
md5(testCase);
}).to.throwError(/input is invalid type/);
});
});
});
context('when large size', function () {
var hash = md5.create();
hash.bytes = 4294967295;
hash.update('any');
expect(hash.hBytes).to.be(1);
});
});
describe('#bas64', function () {
for (var testCaseName in base64TestCases) {
var testCase = base64TestCases[testCaseName];
context('when ' + testCaseName, function () {
for (var hash in testCase) {
(function (message, hash) {
it('should be equal', function () {
expect(md5.base64(message)).to.be(hash);
expect(md5.create().update(message).base64()).to.be(hash);
expect(md5.update(message).base64()).to.be(hash);
});
})(testCase[hash], hash);
}
});
}
});
});
})(md5);
+21
View File
@@ -0,0 +1,21 @@
(function (Worker, WORKER, SOURCE) {
var cases = {
'd41d8cd98f00b204e9800998ecf8427e': '',
'9e107d9d372bb6826bd81d3542a419d6': 'The quick brown fox jumps over the lazy dog',
'e4d909c290d0fb1ca068ffaddf22cbd0': 'The quick brown fox jumps over the lazy dog.'
};
describe('#md5', function () {
Object.keys(cases).forEach(function (hash) {
it('should be equal', function (done) {
var worker = new Worker(WORKER);
worker.onmessage = function(event) {
expect(event.data).to.be(hash);
done();
};
worker.postMessage(SOURCE);
worker.postMessage(cases[hash]);
});
});
});
})(Worker, WORKER, SOURCE);
+26
View File
@@ -0,0 +1,26 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MD5</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/expect.js/index.js"></script>
<script src="../src/md5.js"></script>
</head>
<body>
<div id="mocha"></div>
<script>
WORKER = 'worker.js';
SOURCE = '../src/md5.js';
mocha.setup('bdd');
</script>
<script src="worker-test.js"></script>
<script>
mocha.checkLeaks();
mocha.run();
</script>
<script>
</script>
</body>
</html>
+12
View File
@@ -0,0 +1,12 @@
var imported = false;
onmessage = function(e) {
if (imported) {
postMessage(md5(e.data));
if (typeof exports !== 'undefined') {
imported = false;
}
} else {
imported = true;
importScripts(e.data);
}
}