1
1
'use strict' ;
2
2
3
3
var Buffer = require ( 'safe-buffer' ) . Buffer ;
4
-
5
- var useArrayBuffer = typeof ArrayBuffer !== 'undefined'
6
- && typeof Uint8Array !== 'undefined'
7
- && ArrayBuffer . isView ;
4
+ var toBuffer = require ( 'to-buffer' ) ;
8
5
9
6
// prototype class for hash functions
10
7
function Hash ( blockSize , finalSize ) {
@@ -24,29 +21,9 @@ Hash.prototype.update = function (data, enc) {
24
21
} else if ( typeof data === 'string' ) {
25
22
enc = enc || 'utf8' ;
26
23
data = Buffer . from ( data , enc ) ;
27
- } else if ( useArrayBuffer && ArrayBuffer . isView ( data ) ) {
28
- // Convert all TypedArray and DataView instances to single-byte-wide Uint8Array views
29
- var oldSize = data . byteLength ;
30
- data = new Uint8Array ( data . buffer , data . byteOffset , data . byteLength ) ;
31
-
32
- if ( ! ( data . byteLength === oldSize && data . byteLength === data . length ) ) {
33
- throw new Error ( 'Unexpected: broken Uint8Array' ) ;
34
- }
35
24
} else {
36
- if ( ! data || typeof data !== 'object' || typeof data . length !== 'number' ) {
37
- throw new TypeError ( 'Not an array-like' ) ;
38
- }
39
-
40
- // non-negative 32-bit integer
41
- if ( ( data . length >>> 0 ) !== data . length ) {
42
- throw new RangeError ( 'Invalid length' ) ;
43
- }
44
-
45
- for ( var j = 0 ; j < data . length ; j ++ ) {
46
- if ( ( data [ j ] & 255 ) !== data [ j ] ) {
47
- throw new TypeError ( 'Not a byte array' ) ;
48
- }
49
- }
25
+ enc = enc || 'utf8' ;
26
+ data = toBuffer ( data , enc ) ;
50
27
}
51
28
52
29
var block = this . _block ;
0 commit comments