Added missing arrayBuffer method.

master v0.3.2
Chen, Yi-Cyuan 9 years ago
parent 06519f17db
commit 309beb285b

@ -1,8 +1,13 @@
# Change Log
## v0.3.2 / 2017-01-24
### Added
- missing arrayBuffer method.
## 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.

@ -27,9 +27,14 @@ For node.js, you can use this command to install:
You could use like this:
```JavaScript
md4('Message to hash');
var hash = md4.create();
hash.update('Message to hash');
hash.hex();
var hash2 = md4.update('Message to hash');
hash2.update('Message2 to hash');
hash2.array();
```
If you use node.js, you should require the module first:
```JavaScript

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

4
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#line114">line 114</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line132">line 132</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#line480">line 480</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line498">line 498</a>
</li></ul></dd>
@ -314,7 +314,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#line492">line 492</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line510">line 510</a>
</li></ul></dd>
@ -432,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#line514">line 514</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line532">line 532</a>
</li></ul></dd>
@ -548,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#line458">line 458</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line476">line 476</a>
</li></ul></dd>
@ -664,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#line413">line 413</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line431">line 431</a>
</li></ul></dd>
@ -780,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#line446">line 446</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line464">line 464</a>
</li></ul></dd>
@ -954,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#line142">line 142</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line160">line 160</a>
</li></ul></dd>
@ -1031,7 +1031,7 @@
<br class="clear">
<footer>
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)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Jan 24 2017 15:15:12 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#line532">line 532</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line550">line 550</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.3</a> on Mon Jan 23 2017 15:12:38 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Jan 24 2017 15:15:12 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -52,9 +52,14 @@
<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>
hash.hex();
var hash2 = md4.update('Message to hash');
hash2.update('Message2 to hash');
hash2.array();</code></pre><p>If you use node.js, you should require the module first:</p>
<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) {
// ...
@ -93,7 +98,7 @@ md4.arrayBuffer(''); // ArrayBuffer</code></pre><h2>License</h2><p>The project i
<br class="clear">
<footer>
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)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Jan 24 2017 15:15:12 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.1</li></ul></dd>
<dd class="tag-version"><ul class="dummy"><li>0.3.2</li></ul></dd>
@ -1085,7 +1085,7 @@
<br class="clear">
<footer>
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)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Jan 24 2017 15:15:12 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -30,7 +30,7 @@
* [js-md4]{@link https://github.com/emn178/js-md4}
*
* @namespace md4
* @version 0.3.1
* @version 0.3.2
* @author Yi-Cyuan Chen [emn178@gmail.com]
* @copyright Yi-Cyuan Chen 2015-2027
* @license MIT
@ -50,7 +50,7 @@
var HEX_CHARS = '0123456789abcdef'.split('');
var EXTRA = [128, 32768, 8388608, -2147483648];
var SHIFT = [0, 8, 16, 24];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer'];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer'];
var blocks = [], buffer8;
if (ARRAY_BUFFER) {
@ -125,6 +125,9 @@
*/
var createMethod = function () {
var method = createOutputMethod('hex');
if (NODE_JS) {
method = nodeWrap(method);
}
method.create = function () {
return new Md4();
};
@ -138,6 +141,21 @@
return method;
};
var nodeWrap = function (method) {
var crypto = require('crypto');
var Buffer = require('buffer').Buffer;
var nodeMethod = function (message) {
if (typeof message === 'string') {
return crypto.createHash('md4').update(message, 'utf8').digest('hex');
} else if (ARRAY_BUFFER &amp;&amp; message instanceof ArrayBuffer) {
message = new Uint8Array(message);
} else if (message.length === undefined) {
return method(message);
}
return crypto.createHash('md4').update(new Buffer(message)).digest('hex');
};
return nodeMethod;
};
/**
* Md4 class
@ -181,7 +199,7 @@
return;
}
var notString = typeof message !== 'string';
if(notString &amp;&amp; ARRAY_BUFFER &amp;&amp; message instanceof ArrayBuffer) {
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;
@ -598,7 +616,7 @@
<br class="clear">
<footer>
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)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Jan 24 2017 15:15:12 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -1,6 +1,6 @@
{
"name": "js-md4",
"version": "0.3.1",
"version": "0.3.2",
"description": "A simple MD4 hash function for JavaScript supports UTF-8 encoding.",
"main": "src/md4.js",
"devDependencies": {

@ -2,7 +2,7 @@
* [js-md4]{@link https://github.com/emn178/js-md4}
*
* @namespace md4
* @version 0.3.1
* @version 0.3.2
* @author Yi-Cyuan Chen [emn178@gmail.com]
* @copyright Yi-Cyuan Chen 2015-2027
* @license MIT
@ -22,7 +22,7 @@
var HEX_CHARS = '0123456789abcdef'.split('');
var EXTRA = [128, 32768, 8388608, -2147483648];
var SHIFT = [0, 8, 16, 24];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer'];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer'];
var blocks = [], buffer8;
if (ARRAY_BUFFER) {
@ -97,6 +97,9 @@
*/
var createMethod = function () {
var method = createOutputMethod('hex');
if (NODE_JS) {
method = nodeWrap(method);
}
method.create = function () {
return new Md4();
};
@ -110,6 +113,21 @@
return method;
};
var nodeWrap = function (method) {
var crypto = require('crypto');
var Buffer = require('buffer').Buffer;
var nodeMethod = function (message) {
if (typeof message === 'string') {
return crypto.createHash('md4').update(message, 'utf8').digest('hex');
} else if (ARRAY_BUFFER && message instanceof ArrayBuffer) {
message = new Uint8Array(message);
} else if (message.length === undefined) {
return method(message);
}
return crypto.createHash('md4').update(new Buffer(message)).digest('hex');
};
return nodeMethod;
};
/**
* Md4 class
@ -153,7 +171,7 @@
return;
}
var notString = typeof message !== 'string';
if(notString && ARRAY_BUFFER && message instanceof ArrayBuffer) {
if (notString && ARRAY_BUFFER && message instanceof ArrayBuffer) {
message = new Uint8Array(message);
}
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;

@ -4,7 +4,7 @@
var hex = '';
for (var i = 0; i < array.length; ++i) {
var c = array[i].toString('16');
hex += c.length == 1 ? '0' + c : c;
hex += c.length === 1 ? '0' + c : c;
}
return hex;
};
@ -141,26 +141,26 @@
delete testCases['ArrayBuffer'];
}
methods.forEach(function (method) {
describe('#' + method.name, function() {
for (var testCaseName in testCases) {
(function (testCaseName) {
var testCase = testCases[testCaseName];
context('when ' + testCaseName, function() {
for(var hash in testCase) {
(function (message, hash) {
it('should be equal', function() {
expect(method.call(message)).to.be(hash);
});
})(testCase[hash], hash);
}
});
})(testCaseName);
}
describe('Md4', function () {
methods.forEach(function (method) {
describe('#' + method.name, function() {
for (var testCaseName in testCases) {
(function (testCaseName) {
var testCase = testCases[testCaseName];
context('when ' + testCaseName, function() {
for(var hash in testCase) {
(function (message, hash) {
it('should be equal', function() {
expect(method.call(message)).to.be(hash);
});
})(testCase[hash], hash);
}
});
})(testCaseName);
}
});
});
});
describe('Md4', function () {
classMethods.forEach(function (method) {
describe('#' + method.name, function() {
for (var testCaseName in testCases) {

Loading…
Cancel
Save