mirror of
https://github.com/emn178/js-md5.git
synced 2026-11-18 16:08:52 +08:00
### Fixed
- Incorrect hash for `DataView` input. - Throws `ArrayBuffer is not defined` in browsers without `ArrayBuffer`. ### Changed - Multi-byte typed arrays such as `Uint16Array`, `Uint32Array` and `Float32Array` are now hashed by their underlying bytes, the same as Node.js `crypto` and Web Crypto. Previously each element was treated as one byte. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c2a7870840
commit
66db5dbd99
@@ -1,5 +1,13 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## v0.11.0 / 2026-11-18
|
||||||
|
### Fixed
|
||||||
|
- Incorrect hash for `DataView` input.
|
||||||
|
- Throws `ArrayBuffer is not defined` in browsers without `ArrayBuffer`.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Multi-byte typed arrays such as `Uint16Array`, `Uint32Array` and `Float32Array` are now hashed by their underlying bytes, the same as Node.js `crypto` and Web Crypto. Previously each element was treated as one byte.
|
||||||
|
|
||||||
## v0.10.0 / 2026-11-16
|
## v0.10.0 / 2026-11-16
|
||||||
### Fixed
|
### Fixed
|
||||||
- Unpaired UTF-16 surrogates produce wrong digests and consume the next code unit in the JS path. Unpaired surrogates are now encoded as U+FFFD, matching `TextEncoder` and Node.js `crypto`. #57
|
- Unpaired UTF-16 surrogates produce wrong digests and consume the next code unit in the JS path. Unpaired surrogates are now encoded as U+FFFD, matching `TextEncoder` and Node.js `crypto`. #57
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffad
|
|||||||
// It also supports UTF-8 encoding
|
// It also supports UTF-8 encoding
|
||||||
md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
|
md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
|
||||||
|
|
||||||
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
|
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` and other `ArrayBuffer` views (their underlying bytes are hashed)
|
||||||
md5([]); // d41d8cd98f00b204e9800998ecf8427e
|
md5([]); // d41d8cd98f00b204e9800998ecf8427e
|
||||||
md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
|
md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "js-md5",
|
"name": "js-md5",
|
||||||
"version": "0.10.0",
|
"version": "0.11.0",
|
||||||
"main": ["src/md5.js"],
|
"main": ["src/md5.js"],
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"tests"
|
"tests"
|
||||||
|
|||||||
+10
-4
@@ -2,7 +2,7 @@
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.10.0
|
* @version 0.11.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
var isArray = Array.isArray;
|
var isArray = Array.isArray;
|
||||||
|
|
||||||
var isView = ArrayBuffer.isView;
|
var isView = ArrayBuffer.isView ;
|
||||||
|
|
||||||
// [message: string, isString: bool]
|
// [message: string, isString: bool]
|
||||||
var formatMessage = function (message) {
|
var formatMessage = function (message) {
|
||||||
@@ -53,10 +53,14 @@
|
|||||||
if (message.constructor === ArrayBuffer) {
|
if (message.constructor === ArrayBuffer) {
|
||||||
return [new Uint8Array(message), false];
|
return [new Uint8Array(message), false];
|
||||||
}
|
}
|
||||||
if (!isArray(message) && !isView(message)) {
|
if (isArray(message)) {
|
||||||
|
return [message, false];
|
||||||
|
}
|
||||||
|
if (!isView(message)) {
|
||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
}
|
}
|
||||||
return [message, false];
|
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||||
|
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,6 +176,8 @@
|
|||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
} else if (message.constructor === ArrayBuffer) {
|
} else if (message.constructor === ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
|
} else if (isView(message) && message.constructor !== Buffer) {
|
||||||
|
message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isArray(message) || isView(message) ||
|
if (isArray(message) || isView(message) ||
|
||||||
|
|||||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+8
-4
@@ -8,7 +8,7 @@ var md5$1 = {exports: {}};
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.10.0
|
* @version 0.11.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -42,7 +42,7 @@ var md5$1 = {exports: {}};
|
|||||||
|
|
||||||
var isArray = Array.isArray;
|
var isArray = Array.isArray;
|
||||||
|
|
||||||
var isView = ArrayBuffer.isView;
|
var isView = ArrayBuffer.isView ;
|
||||||
|
|
||||||
// [message: string, isString: bool]
|
// [message: string, isString: bool]
|
||||||
var formatMessage = function (message) {
|
var formatMessage = function (message) {
|
||||||
@@ -56,10 +56,14 @@ var md5$1 = {exports: {}};
|
|||||||
if (message.constructor === ArrayBuffer) {
|
if (message.constructor === ArrayBuffer) {
|
||||||
return [new Uint8Array(message), false];
|
return [new Uint8Array(message), false];
|
||||||
}
|
}
|
||||||
if (!isArray(message) && !isView(message)) {
|
if (isArray(message)) {
|
||||||
|
return [message, false];
|
||||||
|
}
|
||||||
|
if (!isView(message)) {
|
||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
}
|
}
|
||||||
return [message, false];
|
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||||
|
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+10
-4
@@ -13,7 +13,7 @@ var md5$1 = {exports: {}};
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.10.0
|
* @version 0.11.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -51,7 +51,7 @@ var md5$1 = {exports: {}};
|
|||||||
|
|
||||||
var isArray = Array.isArray;
|
var isArray = Array.isArray;
|
||||||
|
|
||||||
var isView = ArrayBuffer.isView;
|
var isView = ArrayBuffer.isView ;
|
||||||
|
|
||||||
// [message: string, isString: bool]
|
// [message: string, isString: bool]
|
||||||
var formatMessage = function (message) {
|
var formatMessage = function (message) {
|
||||||
@@ -65,10 +65,14 @@ var md5$1 = {exports: {}};
|
|||||||
if (message.constructor === ArrayBuffer) {
|
if (message.constructor === ArrayBuffer) {
|
||||||
return [new Uint8Array(message), false];
|
return [new Uint8Array(message), false];
|
||||||
}
|
}
|
||||||
if (!isArray(message) && !isView(message)) {
|
if (isArray(message)) {
|
||||||
|
return [message, false];
|
||||||
|
}
|
||||||
|
if (!isView(message)) {
|
||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
}
|
}
|
||||||
return [message, false];
|
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||||
|
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,6 +188,8 @@ var md5$1 = {exports: {}};
|
|||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
} else if (message.constructor === ArrayBuffer) {
|
} else if (message.constructor === ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
|
} else if (isView(message) && message.constructor !== Buffer) {
|
||||||
|
message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isArray(message) || isView(message) ||
|
if (isArray(message) || isView(message) ||
|
||||||
|
|||||||
+10
-4
@@ -2,7 +2,7 @@
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.10.0
|
* @version 0.11.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var isView = ArrayBuffer.isView;
|
var isView = ARRAY_BUFFER ? ArrayBuffer.isView : null;
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
||||||
isView = function (obj) {
|
isView = function (obj) {
|
||||||
@@ -78,10 +78,14 @@
|
|||||||
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
||||||
return [new Uint8Array(message), false];
|
return [new Uint8Array(message), false];
|
||||||
}
|
}
|
||||||
if (!isArray(message) && !isView(message)) {
|
if (isArray(message)) {
|
||||||
|
return [message, false];
|
||||||
|
}
|
||||||
|
if (!ARRAY_BUFFER || !isView(message)) {
|
||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
}
|
}
|
||||||
return [message, false];
|
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||||
|
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -202,6 +206,8 @@
|
|||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
} else if (message.constructor === ArrayBuffer) {
|
} else if (message.constructor === ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
|
} else if (ARRAY_BUFFER && isView(message) && message.constructor !== Buffer) {
|
||||||
|
message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isArray(message) || isView(message) ||
|
if (isArray(message) || isView(message) ||
|
||||||
|
|||||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
+2
-2
File diff suppressed because one or more lines are too long
+8
-4
@@ -8,7 +8,7 @@ var md5$1 = {exports: {}};
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.10.0
|
* @version 0.11.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -61,7 +61,7 @@ var md5$1 = {exports: {}};
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var isView = ArrayBuffer.isView;
|
var isView = ARRAY_BUFFER ? ArrayBuffer.isView : null;
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
||||||
isView = function (obj) {
|
isView = function (obj) {
|
||||||
@@ -81,10 +81,14 @@ var md5$1 = {exports: {}};
|
|||||||
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
||||||
return [new Uint8Array(message), false];
|
return [new Uint8Array(message), false];
|
||||||
}
|
}
|
||||||
if (!isArray(message) && !isView(message)) {
|
if (isArray(message)) {
|
||||||
|
return [message, false];
|
||||||
|
}
|
||||||
|
if (!ARRAY_BUFFER || !isView(message)) {
|
||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
}
|
}
|
||||||
return [message, false];
|
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||||
|
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+10
-4
@@ -2,7 +2,7 @@
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.10.0
|
* @version 0.11.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
var isArray = Array.isArray;
|
var isArray = Array.isArray;
|
||||||
|
|
||||||
var isView = ArrayBuffer.isView;
|
var isView = ArrayBuffer.isView ;
|
||||||
|
|
||||||
// [message: string, isString: bool]
|
// [message: string, isString: bool]
|
||||||
var formatMessage = function (message) {
|
var formatMessage = function (message) {
|
||||||
@@ -63,10 +63,14 @@
|
|||||||
if (message.constructor === ArrayBuffer) {
|
if (message.constructor === ArrayBuffer) {
|
||||||
return [new Uint8Array(message), false];
|
return [new Uint8Array(message), false];
|
||||||
}
|
}
|
||||||
if (!isArray(message) && !isView(message)) {
|
if (isArray(message)) {
|
||||||
|
return [message, false];
|
||||||
|
}
|
||||||
|
if (!isView(message)) {
|
||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
}
|
}
|
||||||
return [message, false];
|
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||||
|
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,6 +186,8 @@
|
|||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
} else if (message.constructor === ArrayBuffer) {
|
} else if (message.constructor === ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
|
} else if (isView(message) && message.constructor !== Buffer) {
|
||||||
|
message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isArray(message) || isView(message) ||
|
if (isArray(message) || isView(message) ||
|
||||||
|
|||||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -8,7 +8,7 @@ var md5$1 = {exports: {}};
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.10.0
|
* @version 0.11.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -52,7 +52,7 @@ var md5$1 = {exports: {}};
|
|||||||
|
|
||||||
var isArray = Array.isArray;
|
var isArray = Array.isArray;
|
||||||
|
|
||||||
var isView = ArrayBuffer.isView;
|
var isView = ArrayBuffer.isView ;
|
||||||
|
|
||||||
// [message: string, isString: bool]
|
// [message: string, isString: bool]
|
||||||
var formatMessage = function (message) {
|
var formatMessage = function (message) {
|
||||||
@@ -66,10 +66,14 @@ var md5$1 = {exports: {}};
|
|||||||
if (message.constructor === ArrayBuffer) {
|
if (message.constructor === ArrayBuffer) {
|
||||||
return [new Uint8Array(message), false];
|
return [new Uint8Array(message), false];
|
||||||
}
|
}
|
||||||
if (!isArray(message) && !isView(message)) {
|
if (isArray(message)) {
|
||||||
|
return [message, false];
|
||||||
|
}
|
||||||
|
if (!isView(message)) {
|
||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
}
|
}
|
||||||
return [message, false];
|
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||||
|
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ var md5$1 = {exports: {}};
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.10.0
|
* @version 0.11.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -61,7 +61,7 @@ var md5$1 = {exports: {}};
|
|||||||
|
|
||||||
var isArray = Array.isArray;
|
var isArray = Array.isArray;
|
||||||
|
|
||||||
var isView = ArrayBuffer.isView;
|
var isView = ArrayBuffer.isView ;
|
||||||
|
|
||||||
// [message: string, isString: bool]
|
// [message: string, isString: bool]
|
||||||
var formatMessage = function (message) {
|
var formatMessage = function (message) {
|
||||||
@@ -75,10 +75,14 @@ var md5$1 = {exports: {}};
|
|||||||
if (message.constructor === ArrayBuffer) {
|
if (message.constructor === ArrayBuffer) {
|
||||||
return [new Uint8Array(message), false];
|
return [new Uint8Array(message), false];
|
||||||
}
|
}
|
||||||
if (!isArray(message) && !isView(message)) {
|
if (isArray(message)) {
|
||||||
|
return [message, false];
|
||||||
|
}
|
||||||
|
if (!isView(message)) {
|
||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
}
|
}
|
||||||
return [message, false];
|
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||||
|
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -194,6 +198,8 @@ var md5$1 = {exports: {}};
|
|||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
} else if (message.constructor === ArrayBuffer) {
|
} else if (message.constructor === ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
|
} else if (isView(message) && message.constructor !== Buffer) {
|
||||||
|
message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isArray(message) || isView(message) ||
|
if (isArray(message) || isView(message) ||
|
||||||
|
|||||||
+10
-4
@@ -13,7 +13,7 @@ var md5$1 = {exports: {}};
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.10.0
|
* @version 0.11.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -70,7 +70,7 @@ var md5$1 = {exports: {}};
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var isView = ArrayBuffer.isView;
|
var isView = ARRAY_BUFFER ? ArrayBuffer.isView : null;
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
||||||
isView = function (obj) {
|
isView = function (obj) {
|
||||||
@@ -90,10 +90,14 @@ var md5$1 = {exports: {}};
|
|||||||
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
||||||
return [new Uint8Array(message), false];
|
return [new Uint8Array(message), false];
|
||||||
}
|
}
|
||||||
if (!isArray(message) && !isView(message)) {
|
if (isArray(message)) {
|
||||||
|
return [message, false];
|
||||||
|
}
|
||||||
|
if (!ARRAY_BUFFER || !isView(message)) {
|
||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
}
|
}
|
||||||
return [message, false];
|
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||||
|
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,6 +218,8 @@ var md5$1 = {exports: {}};
|
|||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
} else if (message.constructor === ArrayBuffer) {
|
} else if (message.constructor === ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
|
} else if (ARRAY_BUFFER && isView(message) && message.constructor !== Buffer) {
|
||||||
|
message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isArray(message) || isView(message) ||
|
if (isArray(message) || isView(message) ||
|
||||||
|
|||||||
+9
-9
@@ -93,7 +93,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line815">line 815</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line821">line 821</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line734">line 734</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line740">line 740</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -351,7 +351,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line746">line 746</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line752">line 752</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -478,7 +478,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line784">line 784</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line790">line 790</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -607,7 +607,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line768">line 768</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line774">line 774</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -734,7 +734,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line712">line 712</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line718">line 718</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -861,7 +861,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line667">line 667</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line673">line 673</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -988,7 +988,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line700">line 700</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line706">line 706</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -1173,7 +1173,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line363">line 363</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line369">line 369</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<dt class="tag-version">Version:</dt>
|
<dt class="tag-version">Version:</dt>
|
||||||
<dd class="tag-version"><ul class="dummy"><li>0.10.0</li></ul></dd>
|
<dd class="tag-version"><ul class="dummy"><li>0.11.0</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line115">line 115</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line119">line 119</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -417,7 +417,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line124">line 124</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line128">line 128</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -590,7 +590,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line143">line 143</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line147">line 147</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -765,7 +765,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line133">line 133</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line137">line 137</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -880,7 +880,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line158">line 158</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line162">line 162</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -1053,7 +1053,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line106">line 106</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line110">line 110</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -1226,7 +1226,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line95">line 95</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line99">line 99</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -1401,7 +1401,7 @@ md5('The quick brown fox jumps over the lazy dog');</code></pre>
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line166">line 166</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line170">line 170</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -214,7 +214,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line900">line 900</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line906">line 906</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -115,7 +115,7 @@ APIs, including <code>hex</code>, <code>array</code>, <code>digest</code>, and <
|
|||||||
<li><a href="https://jsperf.app/jonuhi/9">Async Benchmark (jsperf.app)</a></li>
|
<li><a href="https://jsperf.app/jonuhi/9">Async Benchmark (jsperf.app)</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li>js-md5 is the fastest synchronous MD5 library, but slower than Hash-WASM</li>
|
<li>js-md5 is the fastest for short strings in these benchmarks. For large data, WebAssembly-based libraries (e.g. Hash-WASM) are faster.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="https://github.com/emn178/js-md5/issues/19">File Benchmark - Issue #19</a></li>
|
<li><a href="https://github.com/emn178/js-md5/issues/19">File Benchmark - Issue #19</a></li>
|
||||||
@@ -167,7 +167,7 @@ md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffad
|
|||||||
// It also supports UTF-8 encoding
|
// It also supports UTF-8 encoding
|
||||||
md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
|
md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
|
||||||
|
|
||||||
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
|
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` and other `ArrayBuffer` views (their underlying bytes are hashed)
|
||||||
md5([]); // d41d8cd98f00b204e9800998ecf8427e
|
md5([]); // d41d8cd98f00b204e9800998ecf8427e
|
||||||
md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
|
md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line225">line 225</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line231">line 231</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -252,7 +252,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line251">line 251</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line257">line 257</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -457,7 +457,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line261">line 261</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line267">line 267</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -662,7 +662,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line282">line 282</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line288">line 288</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -869,7 +869,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line271">line 271</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line277">line 277</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -1042,7 +1042,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line298">line 298</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line304">line 304</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -1247,7 +1247,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line241">line 241</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line247">line 247</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -1452,7 +1452,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line228">line 228</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line234">line 234</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -1659,7 +1659,7 @@ md5.hmac('key', 'The quick brown fox jumps over the lazy dog');</code></pre>
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line307">line 307</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line313">line 313</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -93,7 +93,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line335">line 335</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line341">line 341</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line734">line 734</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line740">line 740</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -330,7 +330,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line746">line 746</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line752">line 752</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -452,7 +452,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line784">line 784</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line790">line 790</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -576,7 +576,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line768">line 768</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line774">line 774</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -698,7 +698,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line712">line 712</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line718">line 718</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -820,7 +820,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line667">line 667</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line673">line 673</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -942,7 +942,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line700">line 700</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line706">line 706</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -1122,7 +1122,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line363">line 363</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line369">line 369</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+11
-5
@@ -30,7 +30,7 @@
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.10.0
|
* @version 0.11.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var isView = ArrayBuffer.isView;
|
var isView = ARRAY_BUFFER ? ArrayBuffer.isView : null;
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (FEATURE_LEGACY && ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
if (FEATURE_LEGACY && ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
||||||
isView = function (obj) {
|
isView = function (obj) {
|
||||||
@@ -114,11 +114,15 @@
|
|||||||
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
||||||
return [new Uint8Array(message), false];
|
return [new Uint8Array(message), false];
|
||||||
}
|
}
|
||||||
if (!isArray(message) && !isView(message)) {
|
if (isArray(message)) {
|
||||||
|
return [message, false];
|
||||||
|
}
|
||||||
|
if (!ARRAY_BUFFER || !isView(message)) {
|
||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
}
|
}
|
||||||
return [message, false];
|
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||||
}
|
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method hex
|
* @method hex
|
||||||
@@ -238,6 +242,8 @@
|
|||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
} else if (message.constructor === ArrayBuffer) {
|
} else if (message.constructor === ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
|
} else if (ARRAY_BUFFER && isView(message) && message.constructor !== Buffer) {
|
||||||
|
message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isArray(message) || isView(message) ||
|
if (isArray(message) || isView(message) ||
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
type Message = string | number[] | ArrayBuffer | Uint8Array;
|
type Message = string | number[] | ArrayBuffer | ArrayBufferView;
|
||||||
|
|
||||||
interface Hasher {
|
interface Hasher {
|
||||||
/**
|
/**
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "js-md5",
|
"name": "js-md5",
|
||||||
"version": "0.10.0",
|
"version": "0.11.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "js-md5",
|
"name": "js-md5",
|
||||||
"version": "0.10.0",
|
"version": "0.11.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^29.0.3",
|
"@rollup/plugin-commonjs": "^29.0.3",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "js-md5",
|
"name": "js-md5",
|
||||||
"version": "0.10.0",
|
"version": "0.11.0",
|
||||||
"description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.",
|
"description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.",
|
||||||
"main": "src/md5.js",
|
"main": "src/md5.js",
|
||||||
"module": "build/md5.mjs",
|
"module": "build/md5.mjs",
|
||||||
|
|||||||
+11
-5
@@ -2,7 +2,7 @@
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.10.0
|
* @version 0.11.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var isView = ArrayBuffer.isView;
|
var isView = ARRAY_BUFFER ? ArrayBuffer.isView : null;
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (FEATURE_LEGACY && ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
if (FEATURE_LEGACY && ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
||||||
isView = function (obj) {
|
isView = function (obj) {
|
||||||
@@ -86,11 +86,15 @@
|
|||||||
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
||||||
return [new Uint8Array(message), false];
|
return [new Uint8Array(message), false];
|
||||||
}
|
}
|
||||||
if (!isArray(message) && !isView(message)) {
|
if (isArray(message)) {
|
||||||
|
return [message, false];
|
||||||
|
}
|
||||||
|
if (!ARRAY_BUFFER || !isView(message)) {
|
||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
}
|
}
|
||||||
return [message, false];
|
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||||
}
|
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method hex
|
* @method hex
|
||||||
@@ -210,6 +214,8 @@
|
|||||||
throw new Error(INPUT_ERROR);
|
throw new Error(INPUT_ERROR);
|
||||||
} else if (message.constructor === ArrayBuffer) {
|
} else if (message.constructor === ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
|
} else if (ARRAY_BUFFER && isView(message) && message.constructor !== Buffer) {
|
||||||
|
message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isArray(message) || isView(message) ||
|
if (isArray(message) || isView(message) ||
|
||||||
|
|||||||
@@ -57,4 +57,14 @@ expect(browserLite.base64).to.be(undefined);
|
|||||||
expect(browserLite.buffer).to.be(undefined);
|
expect(browserLite.buffer).to.be(undefined);
|
||||||
expect(browserLite.hmac).to.be(undefined);
|
expect(browserLite.hmac).to.be(undefined);
|
||||||
|
|
||||||
|
// legacy builds load in browsers without ArrayBuffer
|
||||||
|
['build/md5.js', 'build/md5.min.js'].forEach(function (file) {
|
||||||
|
var context = vm.createContext({});
|
||||||
|
vm.runInContext('var window = this; delete ArrayBuffer; delete Uint8Array; delete Uint32Array; delete DataView;', context);
|
||||||
|
vm.runInContext(fs.readFileSync(file, 'utf8'), context);
|
||||||
|
expect(context.md5('abc')).to.be(EXPECTED_MD5);
|
||||||
|
expect(context.md5.create().update('a').update([98, 99]).hex()).to.be(EXPECTED_MD5);
|
||||||
|
expect(context.md5.hmac('key', 'abc')).to.be(EXPECTED_HMAC);
|
||||||
|
});
|
||||||
|
|
||||||
console.log('Build variants: PASS');
|
console.log('Build variants: PASS');
|
||||||
|
|||||||
@@ -99,6 +99,11 @@
|
|||||||
testCases['Int8Array'] = {
|
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])
|
'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 view'] = {
|
||||||
|
'71f3ccb98530e3072e2eaef01da20d8c': new Int8Array([-1, -128, 65, 0, -2]),
|
||||||
|
'050d144172d916d0846f839e0412e929': new Uint16Array(new Uint8Array([2, 1]).buffer),
|
||||||
|
'eb61eead90e3b899c6bcbe27ac581660': new DataView(new Uint8Array([9, 72, 69, 76, 76, 79, 9]).buffer, 1, 5)
|
||||||
|
};
|
||||||
testCases['ArrayBuffer'] = {
|
testCases['ArrayBuffer'] = {
|
||||||
'93b885adfe0da089cdf634904fd59f71': new ArrayBuffer(1)
|
'93b885adfe0da089cdf634904fd59f71': new ArrayBuffer(1)
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user