Fixed ArrayBuffer dosen't work in Webpack.

master v0.3.1
Chen, Yi-Cyuan 9 years ago
parent 58ea630f45
commit 06519f17db

@ -1,2 +1,2 @@
/node_modules/
/tests/
node_modules/

4
.gitignore vendored

@ -1,2 +1,2 @@
covreporter
node_modules
/node_modules/
/covreporter/

@ -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

@ -1,18 +1,26 @@
# v0.3.0 / 2015-12-28
# Change Log
* Added support for update hash.
* Added support for bytes array output.
* Added support for ArrayBuffer output.
## v0.3.1 / 2017-01-23
### Fixed
- ArrayBuffer dosen't work in Webpack.
### Deprecated
- `buffer` maybe confuse with Buffer in node.js. Please use `arrayBuffer` instead.
# v0.2.0 / 2015-12-01
## v0.3.0 / 2015-12-28
### Added
- support for update hash.
- support for bytes array output.
- support for ArrayBuffer output.
* Added support for bytes.
* Added support for AMD.
## v0.2.0 / 2015-12-01
### Added
- support for bytes.
- support for AMD.
# v0.1.1 / 2015-03-01
## v0.1.1 / 2015-03-01
### Improved
- performance.
Improve performance.
# v0.1.0 / 2015-03-01
Initial release
## v0.1.0 / 2015-03-01
### Added
- initial release.

@ -1,4 +1,4 @@
Copyright 2015 Yi-Cyuan Chen
Copyright 2015-2017 Yi-Cyuan Chen
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

@ -20,6 +20,9 @@ For node.js, you can use this command to install:
npm install js-md4
## Notice
`buffer` method is deprecated. This maybe confuse with Buffer in node.js. Please use `arrayBuffer` instead.
## Usage
You could use like this:
```JavaScript
@ -30,11 +33,11 @@ hash.hex();
```
If you use node.js, you should require the module first:
```JavaScript
md4 = require('js-md4');
var md4 = require('js-md4');
```
It supports AMD:
```JavaScript
require(['your/path/md4.js'], function(md4) {
require(['your/path/md4.js'], function (md4) {
// ...
});
```
@ -58,7 +61,7 @@ md4(''); // 31d6cfe0d16ae931b73c59d7e0c089c0
md4.hex(''); // 31d6cfe0d16ae931b73c59d7e0c089c0
md4.array(''); // [49, 214, 207, 224, 209, 106, 233, 49, 183, 60, 89, 215, 224, 192, 137, 192]
md4.digest(''); // [49, 214, 207, 224, 209, 106, 233, 49, 183, 60, 89, 215, 224, 192, 137, 192]
md4.buffer(''); // ArrayBuffer
md4.arrayBuffer(''); // ArrayBuffer
```
## License
@ -66,4 +69,4 @@ The project is released under the [MIT license](http://www.opensource.org/licens
## Contact
The project's website is located at https://github.com/emn178/js-md4
Author: Yi-Cyuan Chen
Author: Chen, Yi-Cyuan (emn178@gmail.com)

@ -1,6 +1,6 @@
{
"name": "js-md4",
"version": "0.3.0",
"version": "0.3.1",
"main": ["src/md4.js"],
"ignore": [
"samples",

6
build/md4.min.js vendored

File diff suppressed because one or more lines are too long

@ -91,7 +91,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line113">line 113</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line114">line 114</a>
</li></ul></dd>
@ -198,7 +198,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line479">line 479</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line480">line 480</a>
</li></ul></dd>
@ -263,6 +263,122 @@
<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>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line492">line 492</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>md4.arrayBuffer</li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
ArrayBuffer
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">ArrayBuffer</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>hash.arrayBuffer();</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>
@ -302,6 +418,8 @@
<dt class="important tag-deprecated">Deprecated:</dt><dd><ul class="dummy"><li>This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.</li></ul></dd>
@ -314,7 +432,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line491">line 491</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line514">line 514</a>
</li></ul></dd>
@ -430,7 +548,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line457">line 457</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line458">line 458</a>
</li></ul></dd>
@ -546,7 +664,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line412">line 412</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line413">line 413</a>
</li></ul></dd>
@ -662,7 +780,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line445">line 445</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line446">line 446</a>
</li></ul></dd>
@ -836,7 +954,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line141">line 141</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line142">line 142</a>
</li></ul></dd>
@ -913,7 +1031,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 11:56:02 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jan 23 2017 15:12:38 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -210,7 +210,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line518">line 518</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line532">line 532</a>
</li></ul></dd>
@ -285,7 +285,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 11:56:02 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jan 23 2017 15:12:38 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -49,13 +49,14 @@
<h2>Download</h2><p><a href="https://raw.github.com/emn178/js-md4/master/build/md4.min.js">Compress</a><br><a href="https://raw.github.com/emn178/js-md4/master/src/md4.js">Uncompress</a></p>
<h2>Installation</h2><p>You can also install js-md4 by using Bower.</p>
<pre class="prettyprint source"><code>bower install js-md4</code></pre><p>For node.js, you can use this command to install:</p>
<pre class="prettyprint source"><code>npm install js-md4</code></pre><h2>Usage</h2><p>You could use like this:</p>
<pre class="prettyprint source"><code>npm install js-md4</code></pre><h2>Notice</h2><p><code>buffer</code> method is deprecated. This maybe confuse with Buffer in node.js. Please use <code>arrayBuffer</code> instead.</p>
<h2>Usage</h2><p>You could use like this:</p>
<pre class="prettyprint source lang-JavaScript"><code>md4('Message to hash');
var hash = md4.create();
hash.update('Message to hash');
hash.hex();</code></pre><p>If you use node.js, you should require the module first:</p>
<pre class="prettyprint source lang-JavaScript"><code>md4 = require('js-md4');</code></pre><p>It supports AMD:</p>
<pre class="prettyprint source lang-JavaScript"><code>require(['your/path/md4.js'], function(md4) {
<pre class="prettyprint source lang-JavaScript"><code>var md4 = require('js-md4');</code></pre><p>It supports AMD:</p>
<pre class="prettyprint source lang-JavaScript"><code>require(['your/path/md4.js'], function (md4) {
// ...
});</code></pre><p><a href="https://emn178.github.com/js-md4/doc/">See document</a></p>
<h2>Example</h2><pre class="prettyprint source lang-JavaScript"><code>md4(''); // 31d6cfe0d16ae931b73c59d7e0c089c0
@ -74,8 +75,8 @@ md4(''); // 31d6cfe0d16ae931b73c59d7e0c089c0
md4.hex(''); // 31d6cfe0d16ae931b73c59d7e0c089c0
md4.array(''); // [49, 214, 207, 224, 209, 106, 233, 49, 183, 60, 89, 215, 224, 192, 137, 192]
md4.digest(''); // [49, 214, 207, 224, 209, 106, 233, 49, 183, 60, 89, 215, 224, 192, 137, 192]
md4.buffer(''); // ArrayBuffer</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-md4<br>Author: Yi-Cyuan Chen</p></article>
md4.arrayBuffer(''); // ArrayBuffer</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-md4<br>Author: Chen, Yi-Cyuan (emn178@gmail.com)</p></article>
</section>
@ -92,7 +93,7 @@ md4.buffer(''); // ArrayBuffer</code></pre><h2>License</h2><p>The project is rel
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 11:56:02 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jan 23 2017 15:12:38 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -47,7 +47,7 @@
<dt class="tag-version">Version:</dt>
<dd class="tag-version"><ul class="dummy"><li>0.3.0</li></ul></dd>
<dd class="tag-version"><ul class="dummy"><li>0.3.1</li></ul></dd>
@ -75,7 +75,7 @@
<dt class="tag-copyright">Copyright:</dt>
<dd class="tag-copyright"><ul class="dummy"><li>Yi-Cyuan Chen 2015</li></ul></dd>
<dd class="tag-copyright"><ul class="dummy"><li>Yi-Cyuan Chen 2015-2027</li></ul></dd>
@ -233,7 +233,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line53">line 53</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line54">line 54</a>
</li></ul></dd>
@ -400,7 +400,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line62">line 62</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line63">line 63</a>
</li></ul></dd>
@ -509,7 +509,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line77">line 77</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line78">line 78</a>
</li></ul></dd>
@ -676,7 +676,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line44">line 44</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line45">line 45</a>
</li></ul></dd>
@ -843,7 +843,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line33">line 33</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line34">line 34</a>
</li></ul></dd>
@ -1010,7 +1010,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line85">line 85</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line86">line 86</a>
</li></ul></dd>
@ -1085,7 +1085,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 11:56:02 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jan 23 2017 15:12:38 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -30,22 +30,23 @@
* [js-md4]{@link https://github.com/emn178/js-md4}
*
* @namespace md4
* @version 0.3.0
* @version 0.3.1
* @author Yi-Cyuan Chen [emn178@gmail.com]
* @copyright Yi-Cyuan Chen 2015
* @copyright Yi-Cyuan Chen 2015-2027
* @license MIT
*/
(function (root) {
/*jslint bitwise: true */
(function () {
'use strict';
var NODE_JS = typeof process == 'object' &amp;&amp; process.versions &amp;&amp; process.versions.node;
var root = typeof window === 'object' ? window : {};
var NODE_JS = !root.JS_MD4_NO_NODE_JS &amp;&amp; typeof process === 'object' &amp;&amp; process.versions &amp;&amp; process.versions.node;
if (NODE_JS) {
root = global;
}
var COMMON_JS = !root.JS_MD4_TEST &amp;&amp; typeof module == 'object' &amp;&amp; module.exports;
var AMD = typeof define == 'function' &amp;&amp; define.amd;
var ARRAY_BUFFER = !root.JS_MD4_TEST &amp;&amp; typeof ArrayBuffer != 'undefined';
var COMMON_JS = !root.JS_MD4_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_MD4_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];
@ -130,7 +131,7 @@
method.update = function (message) {
return method.create().update(message);
};
for (var i = 0;i &lt; OUTPUT_TYPES.length;++i) {
for (var i = 0; i &lt; OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createOutputMethod(type);
}
@ -179,8 +180,8 @@
if (this.finalized) {
return;
}
var notString = typeof(message) != 'string';
if(notString &amp;&amp; message.constructor == root.ArrayBuffer) {
var notString = typeof message !== 'string';
if(notString &amp;&amp; ARRAY_BUFFER &amp;&amp; message instanceof ArrayBuffer) {
message = new Uint8Array(message);
}
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
@ -198,17 +199,17 @@
if (notString) {
if (ARRAY_BUFFER) {
for (i = this.start;index &lt; length &amp;&amp; i &lt; 64; ++index) {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
buffer8[i++] = message[index];
}
} else {
for (i = this.start;index &lt; length &amp;&amp; i &lt; 64; ++index) {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
blocks[i >> 2] |= message[index] &lt;&lt; SHIFT[i++ &amp; 3];
}
}
} else {
if (ARRAY_BUFFER) {
for (i = this.start;index &lt; length &amp;&amp; i &lt; 64; ++index) {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
code = message.charCodeAt(index);
if (code &lt; 0x80) {
buffer8[i++] = code;
@ -228,7 +229,7 @@
}
}
} else {
for (i = this.start;index &lt; length &amp;&amp; i &lt; 64; ++index) {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
code = message.charCodeAt(index);
if (code &lt; 0x80) {
blocks[i >> 2] |= code &lt;&lt; SHIFT[i++ &amp; 3];
@ -517,16 +518,16 @@
Md4.prototype.array = Md4.prototype.digest;
/**
* @method buffer
* @method arrayBuffer
* @memberof Md4
* @instance
* @description Output hash as ArrayBuffer
* @returns {ArrayBuffer} ArrayBuffer
* @see {@link md4.buffer}
* @see {@link md4.arrayBuffer}
* @example
* hash.buffer();
* hash.arrayBuffer();
*/
Md4.prototype.buffer = function() {
Md4.prototype.arrayBuffer = function() {
this.finalize();
var buffer = new ArrayBuffer(16);
@ -538,6 +539,19 @@
return buffer;
};
/**
* @method buffer
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
* @memberof Md4
* @instance
* @description Output hash as ArrayBuffer
* @returns {ArrayBuffer} ArrayBuffer
* @see {@link md4.buffer}
* @example
* hash.buffer();
*/
Md4.prototype.buffer = Md4.prototype.arrayBuffer;
var exports = createMethod();
if (COMMON_JS) {
@ -567,7 +581,7 @@
});
}
}
}(this));
})();
</code></pre>
</article>
</section>
@ -584,7 +598,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 11:56:02 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jan 23 2017 15:12:38 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -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
{

@ -1,6 +1,6 @@
{
"name": "js-md4",
"version": "0.3.0",
"version": "0.3.1",
"description": "A simple MD4 hash function for JavaScript supports UTF-8 encoding.",
"main": "src/md4.js",
"devDependencies": {
@ -30,7 +30,7 @@
"HMAC"
],
"license": "MIT",
"author": "emn178 <emn178@gmail.com>",
"author": "Chen, Yi-Cyuan <emn178@gmail.com>",
"homepage": "https://github.com/emn178/js-md4",
"bugs": {
"url": "https://github.com/emn178/js-md4/issues"

@ -2,22 +2,23 @@
* [js-md4]{@link https://github.com/emn178/js-md4}
*
* @namespace md4
* @version 0.3.0
* @version 0.3.1
* @author Yi-Cyuan Chen [emn178@gmail.com]
* @copyright Yi-Cyuan Chen 2015
* @copyright Yi-Cyuan Chen 2015-2027
* @license MIT
*/
(function (root) {
/*jslint bitwise: true */
(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_MD4_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
}
var COMMON_JS = !root.JS_MD4_TEST && typeof module == 'object' && module.exports;
var AMD = typeof define == 'function' && define.amd;
var ARRAY_BUFFER = !root.JS_MD4_TEST && typeof ArrayBuffer != 'undefined';
var COMMON_JS = !root.JS_MD4_NO_COMMON_JS && typeof module === 'object' && module.exports;
var AMD = typeof define === 'function' && define.amd;
var ARRAY_BUFFER = !root.JS_MD4_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
var HEX_CHARS = '0123456789abcdef'.split('');
var EXTRA = [128, 32768, 8388608, -2147483648];
var SHIFT = [0, 8, 16, 24];
@ -102,7 +103,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);
}
@ -151,8 +152,8 @@
if (this.finalized) {
return;
}
var notString = typeof(message) != 'string';
if(notString && message.constructor == root.ArrayBuffer) {
var notString = typeof message !== 'string';
if(notString && ARRAY_BUFFER && message instanceof ArrayBuffer) {
message = new Uint8Array(message);
}
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
@ -170,17 +171,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;
@ -200,7 +201,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];
@ -489,16 +490,16 @@
Md4.prototype.array = Md4.prototype.digest;
/**
* @method buffer
* @method arrayBuffer
* @memberof Md4
* @instance
* @description Output hash as ArrayBuffer
* @returns {ArrayBuffer} ArrayBuffer
* @see {@link md4.buffer}
* @see {@link md4.arrayBuffer}
* @example
* hash.buffer();
* hash.arrayBuffer();
*/
Md4.prototype.buffer = function() {
Md4.prototype.arrayBuffer = function() {
this.finalize();
var buffer = new ArrayBuffer(16);
@ -510,6 +511,19 @@
return buffer;
};
/**
* @method buffer
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
* @memberof Md4
* @instance
* @description Output hash as ArrayBuffer
* @returns {ArrayBuffer} ArrayBuffer
* @see {@link md4.buffer}
* @example
* hash.buffer();
*/
Md4.prototype.buffer = Md4.prototype.arrayBuffer;
var exports = createMethod();
if (COMMON_JS) {
@ -539,4 +553,4 @@
});
}
}
}(this));
})();

@ -1,12 +1,38 @@
md4 = require('../src/md4.js');
// Node.js env
expect = require('expect.js');
md4 = require('../src/md4.js');
require('./test.js');
delete require.cache[require.resolve('../src/md4.js')]
delete require.cache[require.resolve('./test.js')]
md4 = null
JS_MD4_TEST = true;
// Webpack browser env
JS_MD4_NO_NODE_JS = true;
window = global;
md4 = require('../src/md4.js');
require('./test.js');
delete require.cache[require.resolve('../src/md4.js')];
delete require.cache[require.resolve('./test.js')];
md4 = null;
// browser env
JS_MD4_NO_NODE_JS = true;
JS_MD4_NO_COMMON_JS = true;
window = global;
require('../src/md4.js');
require('./test.js');
delete require.cache[require.resolve('../src/md4.js')];
delete require.cache[require.resolve('./test.js')];
md4 = null;
// browser env and no array buffer
JS_MD4_NO_NODE_JS = true;
JS_MD4_NO_COMMON_JS = true;
JS_MD4_NO_ARRAY_BUFFER = true;
window = global;
require('../src/md4.js');
require('./test.js');
@ -14,7 +40,12 @@ delete require.cache[require.resolve('../src/md4.js')];
delete require.cache[require.resolve('./test.js')];
md4 = null;
define = function(func) {
// browser AMD
JS_MD4_NO_NODE_JS = true;
JS_MD4_NO_COMMON_JS = true;
JS_MD4_NO_ARRAY_BUFFER = undefined;
window = global;
define = function (func) {
md4 = func();
require('./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;
}
@ -53,7 +53,6 @@
'47c61a0fa8738ba77308a8a600f88e4b': new ArrayBuffer(1)
},
'Object': {
'31d6cfe0d16ae931b73c59d7e0c089c0': {},
'31d6cfe0d16ae931b73c59d7e0c089c0': {what: 'ever'}
}
};
@ -119,9 +118,9 @@
}
},
{
name: 'buffer',
name: 'arrayBuffer',
call: function (message) {
return md4.update(message).buffer().toHexString();
return md4.update(message).arrayBuffer().toHexString();
}
},
{
@ -135,14 +134,21 @@
}
];
if (typeof JS_MD4_NO_ARRAY_BUFFER !== 'undefined') {
classMethods = classMethods.filter(function (method) {
return method.name != 'arrayBuffer';
});
delete testCases['ArrayBuffer'];
}
methods.forEach(function (method) {
describe('#' + method.name, function() {
for(var testCaseName in testCases) {
(function(testCaseName) {
for (var testCaseName in testCases) {
(function (testCaseName) {
var testCase = testCases[testCaseName];
context('when ' + testCaseName, function() {
for(var hash in testCase) {
(function(message, hash) {
(function (message, hash) {
it('should be equal', function() {
expect(method.call(message)).to.be(hash);
});
@ -154,15 +160,15 @@
});
});
describe('Md4', function() {
describe('Md4', function () {
classMethods.forEach(function (method) {
describe('#' + method.name, function() {
for(var testCaseName in testCases) {
(function(testCaseName) {
for (var testCaseName in testCases) {
(function (testCaseName) {
var testCase = testCases[testCaseName];
context('when ' + testCaseName, function() {
for(var hash in testCase) {
(function(message, hash) {
(function (message, hash) {
it('should be equal', function() {
expect(method.call(message)).to.be(hash);
});

Loading…
Cancel
Save