From 06519f17db75402f679b8418a3342ea2afd51285 Mon Sep 17 00:00:00 2001 From: "Chen, Yi-Cyuan" Date: Mon, 23 Jan 2017 15:14:14 +0800 Subject: [PATCH] Fixed ArrayBuffer dosen't work in Webpack. --- .covignore | 2 +- .gitignore | 4 +- .travis.yml | 8 +-- CHANGELOG.md | 34 +++++---- LICENSE.txt | 2 +- README.md | 11 +-- bower.json | 2 +- build/md4.min.js | 6 +- doc/Md4_.html | 134 ++++++++++++++++++++++++++++++++--- doc/global.html | 4 +- doc/index.html | 13 ++-- doc/md4.html | 18 ++--- doc/md4.js.html | 86 ++++++++++++---------- doc/styles/jsdoc-default.css | 67 +++++++++--------- package.json | 4 +- src/md4.js | 84 +++++++++++++--------- tests/node-test.js | 37 +++++++++- tests/test.js | 28 +++++--- 18 files changed, 369 insertions(+), 175 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 2a5c298..631dab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/LICENSE.txt b/LICENSE.txt index 68b5543..a2f73fd 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -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 diff --git a/README.md b/README.md index d8cc4c9..a75426e 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/bower.json b/bower.json index cc9e824..5929af4 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "js-md4", - "version": "0.3.0", + "version": "0.3.1", "main": ["src/md4.js"], "ignore": [ "samples", diff --git a/build/md4.min.js b/build/md4.min.js index cc3fb8f..41401d3 100644 --- a/build/md4.min.js +++ b/build/md4.min.js @@ -2,9 +2,9 @@ * [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(t){"use strict";function i(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=s;else if(n){var i=new ArrayBuffer(68);this.buffer8=new Uint8Array(i),this.blocks=new Uint32Array(i)}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 h="object"==typeof process&&process.versions&&process.versions.node;h&&(t=global);var s,e=!t.JS_MD4_TEST&&"object"==typeof module&&module.exports,r="function"==typeof define&&define.amd,n=!t.JS_MD4_TEST&&"undefined"!=typeof ArrayBuffer,o="0123456789abcdef".split(""),a=[128,32768,8388608,-2147483648],f=[0,8,16,24],u=["hex","array","digest","buffer"],c=[];if(n){var p=new ArrayBuffer(68);s=new Uint8Array(p),c=new Uint32Array(p)}var d=function(t){return function(h){return new i(!0).update(h)[t]()}},y=function(){var t=d("hex");t.create=function(){return new i},t.update=function(i){return t.create().update(i)};for(var h=0;hr;){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),h)if(n)for(e=this.start;o>r&&64>e;++r)u[e++]=i[r];else for(e=this.start;o>r&&64>e;++r)a[e>>2]|=i[r]<r&&64>e;++r)s=i.charCodeAt(r),128>s?u[e++]=s:2048>s?(u[e++]=192|s>>6,u[e++]=128|63&s):55296>s||s>=57344?(u[e++]=224|s>>12,u[e++]=128|s>>6&63,u[e++]=128|63&s):(s=65536+((1023&s)<<10|1023&i.charCodeAt(++r)),u[e++]=240|s>>18,u[e++]=128|s>>12&63,u[e++]=128|s>>6&63,u[e++]=128|63&s);else for(e=this.start;o>r&&64>e;++r)s=i.charCodeAt(r),128>s?a[e>>2]|=s<s?(a[e>>2]|=(192|s>>6)<>2]|=(128|63&s)<s||s>=57344?(a[e>>2]|=(224|s>>12)<>2]|=(128|s>>6&63)<>2]|=(128|63&s)<>2]|=(240|s>>18)<>2]|=(128|s>>12&63)<>2]|=(128|s>>6&63)<>2]|=(128|63&s)<=64?(this.start=e-64,this.hash(),this.hashed=!0):this.start=e}return this}},i.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,i=this.lastByteIndex;t[i>>2]|=a[3&i],i>=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()}},i.prototype.hash=function(){var t,i,h,s,e,r,n,o,a=this.blocks;this.first?(t=a[0]-1,t=t<<3|t>>>29,s=(4023233417&t|2562383102&~t)+a[1]+271733878,s=s<<7|s>>>25,h=(s&t|4023233417&~s)+a[2]-1732584194,h=h<<11|h>>>21,i=(h&s|~h&t)+a[3]-271733879,i=i<<19|i>>>13):(t=this.h0,i=this.h1,h=this.h2,s=this.h3,t+=(i&h|~i&s)+a[0],t=t<<3|t>>>29,s+=(t&i|~t&h)+a[1],s=s<<7|s>>>25,h+=(s&t|~s&i)+a[2],h=h<<11|h>>>21,i+=(h&s|~h&t)+a[3],i=i<<19|i>>>13),t+=(i&h|~i&s)+a[4],t=t<<3|t>>>29,s+=(t&i|~t&h)+a[5],s=s<<7|s>>>25,h+=(s&t|~s&i)+a[6],h=h<<11|h>>>21,i+=(h&s|~h&t)+a[7],i=i<<19|i>>>13,t+=(i&h|~i&s)+a[8],t=t<<3|t>>>29,s+=(t&i|~t&h)+a[9],s=s<<7|s>>>25,h+=(s&t|~s&i)+a[10],h=h<<11|h>>>21,i+=(h&s|~h&t)+a[11],i=i<<19|i>>>13,t+=(i&h|~i&s)+a[12],t=t<<3|t>>>29,s+=(t&i|~t&h)+a[13],s=s<<7|s>>>25,h+=(s&t|~s&i)+a[14],h=h<<11|h>>>21,i+=(h&s|~h&t)+a[15],i=i<<19|i>>>13,r=i&h,t+=(r|i&s|h&s)+a[0]+1518500249,t=t<<3|t>>>29,e=t&i,s+=(e|t&h|r)+a[4]+1518500249,s=s<<5|s>>>27,o=s&t,h+=(o|s&i|e)+a[8]+1518500249,h=h<<9|h>>>23,n=h&s,i+=(n|h&t|o)+a[12]+1518500249,i=i<<13|i>>>19,r=i&h,t+=(r|i&s|n)+a[1]+1518500249,t=t<<3|t>>>29,e=t&i,s+=(e|t&h|r)+a[5]+1518500249,s=s<<5|s>>>27,o=s&t,h+=(o|s&i|e)+a[9]+1518500249,h=h<<9|h>>>23,n=h&s,i+=(n|h&t|o)+a[13]+1518500249,i=i<<13|i>>>19,r=i&h,t+=(r|i&s|n)+a[2]+1518500249,t=t<<3|t>>>29,e=t&i,s+=(e|t&h|r)+a[6]+1518500249,s=s<<5|s>>>27,o=s&t,h+=(o|s&i|e)+a[10]+1518500249,h=h<<9|h>>>23,n=h&s,i+=(n|h&t|o)+a[14]+1518500249,i=i<<13|i>>>19,r=i&h,t+=(r|i&s|n)+a[3]+1518500249,t=t<<3|t>>>29,e=t&i,s+=(e|t&h|r)+a[7]+1518500249,s=s<<5|s>>>27,o=s&t,h+=(o|s&i|e)+a[11]+1518500249,h=h<<9|h>>>23,i+=(h&s|h&t|o)+a[15]+1518500249,i=i<<13|i>>>19,r=i^h,t+=(r^s)+a[0]+1859775393,t=t<<3|t>>>29,s+=(r^t)+a[8]+1859775393,s=s<<9|s>>>23,o=s^t,h+=(o^i)+a[4]+1859775393,h=h<<11|h>>>21,i+=(o^h)+a[12]+1859775393,i=i<<15|i>>>17,r=i^h,t+=(r^s)+a[2]+1859775393,t=t<<3|t>>>29,s+=(r^t)+a[10]+1859775393,s=s<<9|s>>>23,o=s^t,h+=(o^i)+a[6]+1859775393,h=h<<11|h>>>21,i+=(o^h)+a[14]+1859775393,i=i<<15|i>>>17,r=i^h,t+=(r^s)+a[1]+1859775393,t=t<<3|t>>>29,s+=(r^t)+a[9]+1859775393,s=s<<9|s>>>23,o=s^t,h+=(o^i)+a[5]+1859775393,h=h<<11|h>>>21,i+=(o^h)+a[13]+1859775393,i=i<<15|i>>>17,r=i^h,t+=(r^s)+a[3]+1859775393,t=t<<3|t>>>29,s+=(r^t)+a[11]+1859775393,s=s<<9|s>>>23,o=s^t,h+=(o^i)+a[7]+1859775393,h=h<<11|h>>>21,i+=(o^h)+a[15]+1859775393,i=i<<15|i>>>17,this.first?(this.h0=t+1732584193<<0,this.h1=i-271733879<<0,this.h2=h-1732584194<<0,this.h3=s+271733878<<0,this.first=!1):(this.h0=this.h0+t<<0,this.h1=this.h1+i<<0,this.h2=this.h2+h<<0,this.h3=this.h3+s<<0)},i.prototype.hex=function(){this.finalize();var t=this.h0,i=this.h1,h=this.h2,s=this.h3;return o[t>>4&15]+o[15&t]+o[t>>12&15]+o[t>>8&15]+o[t>>20&15]+o[t>>16&15]+o[t>>28&15]+o[t>>24&15]+o[i>>4&15]+o[15&i]+o[i>>12&15]+o[i>>8&15]+o[i>>20&15]+o[i>>16&15]+o[i>>28&15]+o[i>>24&15]+o[h>>4&15]+o[15&h]+o[h>>12&15]+o[h>>8&15]+o[h>>20&15]+o[h>>16&15]+o[h>>28&15]+o[h>>24&15]+o[s>>4&15]+o[15&s]+o[s>>12&15]+o[s>>8&15]+o[s>>20&15]+o[s>>16&15]+o[s>>28&15]+o[s>>24&15]},i.prototype.toString=i.prototype.hex,i.prototype.digest=function(){this.finalize();var t=this.h0,i=this.h1,h=this.h2,s=this.h3;return[255&t,t>>8&255,t>>16&255,t>>24&255,255&i,i>>8&255,i>>16&255,i>>24&255,255&h,h>>8&255,h>>16&255,h>>24&255,255&s,s>>8&255,s>>16&255,s>>24&255]},i.prototype.array=i.prototype.digest,i.prototype.buffer=function(){this.finalize();var t=new ArrayBuffer(16),i=new Uint32Array(t);return i[0]=this.h0,i[1]=this.h1,i[2]=this.h2,i[3]=this.h3,t};var l=y();e?module.exports=l:(t.md4=l,r&&define(function(){return l}))}(this); \ No newline at end of file +!function(){"use strict";function t(t){if(t)p[0]=p[16]=p[1]=p[2]=p[3]=p[4]=p[5]=p[6]=p[7]=p[8]=p[9]=p[10]=p[11]=p[12]=p[13]=p[14]=p[15]=0,this.blocks=p,this.buffer8=s;else if(n){var i=new ArrayBuffer(68);this.buffer8=new Uint8Array(i),this.blocks=new Uint32Array(i)}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 i="object"==typeof window?window:{},h=!i.JS_MD4_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;h&&(i=global);var s,e=!i.JS_MD4_NO_COMMON_JS&&"object"==typeof module&&module.exports,r="function"==typeof define&&define.amd,n=!i.JS_MD4_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,o="0123456789abcdef".split(""),f=[128,32768,8388608,-2147483648],a=[0,8,16,24],u=["hex","array","digest","buffer"],p=[];if(n){var y=new ArrayBuffer(68);s=new Uint8Array(y),p=new Uint32Array(y)}var c=function(i){return function(h){return new t(!0).update(h)[i]()}},d=function(){var i=c("hex");i.create=function(){return new t},i.update=function(t){return i.create().update(t)};for(var h=0;he;){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),i)if(n)for(s=this.start;r>e&&64>s;++e)f[s++]=t[e];else for(s=this.start;r>e&&64>s;++e)o[s>>2]|=t[e]<e&&64>s;++e)h=t.charCodeAt(e),128>h?f[s++]=h:2048>h?(f[s++]=192|h>>6,f[s++]=128|63&h):55296>h||h>=57344?(f[s++]=224|h>>12,f[s++]=128|h>>6&63,f[s++]=128|63&h):(h=65536+((1023&h)<<10|1023&t.charCodeAt(++e)),f[s++]=240|h>>18,f[s++]=128|h>>12&63,f[s++]=128|h>>6&63,f[s++]=128|63&h);else for(s=this.start;r>e&&64>s;++e)h=t.charCodeAt(e),128>h?o[s>>2]|=h<h?(o[s>>2]|=(192|h>>6)<>2]|=(128|63&h)<h||h>=57344?(o[s>>2]|=(224|h>>12)<>2]|=(128|h>>6&63)<>2]|=(128|63&h)<>2]|=(240|h>>18)<>2]|=(128|h>>12&63)<>2]|=(128|h>>6&63)<>2]|=(128|63&h)<=64?(this.start=s-64,this.hash(),this.hashed=!0):this.start=s}return this}},t.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,i=this.lastByteIndex;t[i>>2]|=f[3&i],i>=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,i,h,s,e,r,n,o,f=this.blocks;this.first?(t=f[0]-1,t=t<<3|t>>>29,s=(4023233417&t|2562383102&~t)+f[1]+271733878,s=s<<7|s>>>25,h=(s&t|4023233417&~s)+f[2]-1732584194,h=h<<11|h>>>21,i=(h&s|~h&t)+f[3]-271733879,i=i<<19|i>>>13):(t=this.h0,i=this.h1,h=this.h2,s=this.h3,t+=(i&h|~i&s)+f[0],t=t<<3|t>>>29,s+=(t&i|~t&h)+f[1],s=s<<7|s>>>25,h+=(s&t|~s&i)+f[2],h=h<<11|h>>>21,i+=(h&s|~h&t)+f[3],i=i<<19|i>>>13),t+=(i&h|~i&s)+f[4],t=t<<3|t>>>29,s+=(t&i|~t&h)+f[5],s=s<<7|s>>>25,h+=(s&t|~s&i)+f[6],h=h<<11|h>>>21,i+=(h&s|~h&t)+f[7],i=i<<19|i>>>13,t+=(i&h|~i&s)+f[8],t=t<<3|t>>>29,s+=(t&i|~t&h)+f[9],s=s<<7|s>>>25,h+=(s&t|~s&i)+f[10],h=h<<11|h>>>21,i+=(h&s|~h&t)+f[11],i=i<<19|i>>>13,t+=(i&h|~i&s)+f[12],t=t<<3|t>>>29,s+=(t&i|~t&h)+f[13],s=s<<7|s>>>25,h+=(s&t|~s&i)+f[14],h=h<<11|h>>>21,i+=(h&s|~h&t)+f[15],i=i<<19|i>>>13,r=i&h,t+=(r|i&s|h&s)+f[0]+1518500249,t=t<<3|t>>>29,e=t&i,s+=(e|t&h|r)+f[4]+1518500249,s=s<<5|s>>>27,o=s&t,h+=(o|s&i|e)+f[8]+1518500249,h=h<<9|h>>>23,n=h&s,i+=(n|h&t|o)+f[12]+1518500249,i=i<<13|i>>>19,r=i&h,t+=(r|i&s|n)+f[1]+1518500249,t=t<<3|t>>>29,e=t&i,s+=(e|t&h|r)+f[5]+1518500249,s=s<<5|s>>>27,o=s&t,h+=(o|s&i|e)+f[9]+1518500249,h=h<<9|h>>>23,n=h&s,i+=(n|h&t|o)+f[13]+1518500249,i=i<<13|i>>>19,r=i&h,t+=(r|i&s|n)+f[2]+1518500249,t=t<<3|t>>>29,e=t&i,s+=(e|t&h|r)+f[6]+1518500249,s=s<<5|s>>>27,o=s&t,h+=(o|s&i|e)+f[10]+1518500249,h=h<<9|h>>>23,n=h&s,i+=(n|h&t|o)+f[14]+1518500249,i=i<<13|i>>>19,r=i&h,t+=(r|i&s|n)+f[3]+1518500249,t=t<<3|t>>>29,e=t&i,s+=(e|t&h|r)+f[7]+1518500249,s=s<<5|s>>>27,o=s&t,h+=(o|s&i|e)+f[11]+1518500249,h=h<<9|h>>>23,i+=(h&s|h&t|o)+f[15]+1518500249,i=i<<13|i>>>19,r=i^h,t+=(r^s)+f[0]+1859775393,t=t<<3|t>>>29,s+=(r^t)+f[8]+1859775393,s=s<<9|s>>>23,o=s^t,h+=(o^i)+f[4]+1859775393,h=h<<11|h>>>21,i+=(o^h)+f[12]+1859775393,i=i<<15|i>>>17,r=i^h,t+=(r^s)+f[2]+1859775393,t=t<<3|t>>>29,s+=(r^t)+f[10]+1859775393,s=s<<9|s>>>23,o=s^t,h+=(o^i)+f[6]+1859775393,h=h<<11|h>>>21,i+=(o^h)+f[14]+1859775393,i=i<<15|i>>>17,r=i^h,t+=(r^s)+f[1]+1859775393,t=t<<3|t>>>29,s+=(r^t)+f[9]+1859775393,s=s<<9|s>>>23,o=s^t,h+=(o^i)+f[5]+1859775393,h=h<<11|h>>>21,i+=(o^h)+f[13]+1859775393,i=i<<15|i>>>17,r=i^h,t+=(r^s)+f[3]+1859775393,t=t<<3|t>>>29,s+=(r^t)+f[11]+1859775393,s=s<<9|s>>>23,o=s^t,h+=(o^i)+f[7]+1859775393,h=h<<11|h>>>21,i+=(o^h)+f[15]+1859775393,i=i<<15|i>>>17,this.first?(this.h0=t+1732584193<<0,this.h1=i-271733879<<0,this.h2=h-1732584194<<0,this.h3=s+271733878<<0,this.first=!1):(this.h0=this.h0+t<<0,this.h1=this.h1+i<<0,this.h2=this.h2+h<<0,this.h3=this.h3+s<<0)},t.prototype.hex=function(){this.finalize();var t=this.h0,i=this.h1,h=this.h2,s=this.h3;return o[t>>4&15]+o[15&t]+o[t>>12&15]+o[t>>8&15]+o[t>>20&15]+o[t>>16&15]+o[t>>28&15]+o[t>>24&15]+o[i>>4&15]+o[15&i]+o[i>>12&15]+o[i>>8&15]+o[i>>20&15]+o[i>>16&15]+o[i>>28&15]+o[i>>24&15]+o[h>>4&15]+o[15&h]+o[h>>12&15]+o[h>>8&15]+o[h>>20&15]+o[h>>16&15]+o[h>>28&15]+o[h>>24&15]+o[s>>4&15]+o[15&s]+o[s>>12&15]+o[s>>8&15]+o[s>>20&15]+o[s>>16&15]+o[s>>28&15]+o[s>>24&15]},t.prototype.toString=t.prototype.hex,t.prototype.digest=function(){this.finalize();var t=this.h0,i=this.h1,h=this.h2,s=this.h3;return[255&t,t>>8&255,t>>16&255,t>>24&255,255&i,i>>8&255,i>>16&255,i>>24&255,255&h,h>>8&255,h>>16&255,h>>24&255,255&s,s>>8&255,s>>16&255,s>>24&255]},t.prototype.array=t.prototype.digest,t.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(16),i=new Uint32Array(t);return i[0]=this.h0,i[1]=this.h1,i[2]=this.h2,i[3]=this.h3,t},t.prototype.buffer=t.prototype.arrayBuffer;var l=d();e?module.exports=l:(i.md4=l,r&&define(function(){return l}))}(); \ No newline at end of file diff --git a/doc/Md4_.html b/doc/Md4_.html index f68f5a6..7ff27c0 100644 --- a/doc/Md4_.html +++ b/doc/Md4_.html @@ -91,7 +91,7 @@
Source:
@@ -198,7 +198,7 @@
Source:
@@ -263,6 +263,122 @@ +

arrayBuffer() → {ArrayBuffer}

+ + + + + +
+ Output hash as ArrayBuffer +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+
    +
  • md4.arrayBuffer
  • +
+
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ ArrayBuffer +
+ + + +
+
+ Type +
+
+ +ArrayBuffer + + +
+
+ + + + +
Example
+ +
hash.arrayBuffer();
+ + + + + + + +

buffer() → {ArrayBuffer}

@@ -302,6 +418,8 @@ +
Deprecated:
  • This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
+ @@ -314,7 +432,7 @@
Source:
@@ -430,7 +548,7 @@
Source:
@@ -546,7 +664,7 @@
Source:
@@ -662,7 +780,7 @@
Source:
@@ -836,7 +954,7 @@
Source:
@@ -913,7 +1031,7 @@
- Documentation generated by JSDoc 3.4.0 on Mon Dec 28 2015 11:56:02 GMT+0800 (CST) + Documentation generated by JSDoc 3.4.3 on Mon Jan 23 2017 15:12:38 GMT+0800 (CST)
diff --git a/doc/global.html b/doc/global.html index 2530ae9..322777b 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 Mon Dec 28 2015 11:56:02 GMT+0800 (CST) + Documentation generated by JSDoc 3.4.3 on Mon Jan 23 2017 15:12:38 GMT+0800 (CST)
diff --git a/doc/index.html b/doc/index.html index 9192d20..bb4b1cd 100644 --- a/doc/index.html +++ b/doc/index.html @@ -49,13 +49,14 @@

Download

Compress
Uncompress

Installation

You can also install js-md4 by using Bower.

bower install js-md4

For node.js, you can use this command to install:

-
npm install js-md4

Usage

You could use like this:

+
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:

md4('Message to hash');
 var hash = md4.create();
 hash.update('Message to hash');
 hash.hex();

If you use node.js, you should require the module first:

-
md4 = require('js-md4');

It supports AMD:

-
require(['your/path/md4.js'], function(md4) {
+
var md4 = require('js-md4');

It supports AMD:

+
require(['your/path/md4.js'], function (md4) {
 // ...
 });

See document

Example

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

License

The project is released under the MIT license.

-

Contact

The project's website is located at https://github.com/emn178/js-md4
Author: Yi-Cyuan Chen

+md4.arrayBuffer(''); // ArrayBuffer

License

The project is released under the MIT license.

+

Contact

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

@@ -92,7 +93,7 @@ md4.buffer(''); // ArrayBuffer

License

The project is rel

- Documentation generated by JSDoc 3.4.0 on Mon Dec 28 2015 11:56:02 GMT+0800 (CST) + Documentation generated by JSDoc 3.4.3 on Mon Jan 23 2017 15:12:38 GMT+0800 (CST)
diff --git a/doc/md4.html b/doc/md4.html index 6b53574..5f08b66 100644 --- a/doc/md4.html +++ b/doc/md4.html @@ -47,7 +47,7 @@
Version:
-
  • 0.3.0
+
  • 0.3.1
@@ -75,7 +75,7 @@ - + @@ -233,7 +233,7 @@
Source:
@@ -400,7 +400,7 @@
Source:
@@ -509,7 +509,7 @@
Source:
@@ -676,7 +676,7 @@
Source:
@@ -843,7 +843,7 @@
Source:
@@ -1010,7 +1010,7 @@
Source:
@@ -1085,7 +1085,7 @@
- Documentation generated by JSDoc 3.4.0 on Mon Dec 28 2015 11:56:02 GMT+0800 (CST) + Documentation generated by JSDoc 3.4.3 on Mon Jan 23 2017 15:12:38 GMT+0800 (CST)
diff --git a/doc/md4.js.html b/doc/md4.js.html index 26fe893..f0a43ff 100644 --- a/doc/md4.js.html +++ b/doc/md4.js.html @@ -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' && 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]; @@ -130,7 +131,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); } @@ -179,8 +180,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; @@ -198,17 +199,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; @@ -228,7 +229,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]; @@ -453,21 +454,21 @@ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3; return HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] + - HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] + - HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] + - HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] + - HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + - HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] + - HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] + - HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] + - HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + - HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] + - HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] + - HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] + - HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + - HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] + - HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] + - HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F]; + HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] + + HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] + + HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] + + HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + + HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] + + HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] + + HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] + + HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + + HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] + + HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] + + HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] + + HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + + HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] + + HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] + + HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F]; }; /** @@ -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)); +})(); @@ -584,7 +598,7 @@
- Documentation generated by JSDoc 3.4.0 on Mon Dec 28 2015 11:56:02 GMT+0800 (CST) + Documentation generated by JSDoc 3.4.3 on Mon Jan 23 2017 15:12:38 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 66e6123..f966b3d 100644 --- a/package.json +++ b/package.json @@ -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 ", + "author": "Chen, Yi-Cyuan ", "homepage": "https://github.com/emn178/js-md4", "bugs": { "url": "https://github.com/emn178/js-md4/issues" diff --git a/src/md4.js b/src/md4.js index 67f0828..7329c96 100644 --- a/src/md4.js +++ b/src/md4.js @@ -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]; @@ -425,21 +426,21 @@ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3; return HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] + - HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] + - HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] + - HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] + - HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + - HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] + - HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] + - HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] + - HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + - HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] + - HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] + - HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] + - HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + - HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] + - HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] + - HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F]; + HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] + + HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] + + HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] + + HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + + HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] + + HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] + + HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] + + HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + + HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] + + HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] + + HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] + + HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + + HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] + + HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] + + HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F]; }; /** @@ -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)); +})(); diff --git a/tests/node-test.js b/tests/node-test.js index 7dfcf92..39b90ed 100644 --- a/tests/node-test.js +++ b/tests/node-test.js @@ -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'); }; diff --git a/tests/test.js b/tests/test.js index dc3553b..376519d 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; } @@ -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); });