@@ -14,10 +14,10 @@ const {
14
14
RSA_PKCS1_PADDING
15
15
} = process . binding ( 'constants' ) . crypto ;
16
16
const {
17
+ checkIsArrayBufferView,
17
18
getDefaultEncoding,
18
19
toBuf
19
20
} = require ( 'internal/crypto/util' ) ;
20
- const { isArrayBufferView } = require ( 'internal/util/types' ) ;
21
21
const { Writable } = require ( 'stream' ) ;
22
22
const { inherits } = require ( 'util' ) ;
23
23
@@ -41,14 +41,7 @@ Sign.prototype._write = function _write(chunk, encoding, callback) {
41
41
42
42
Sign . prototype . update = function update ( data , encoding ) {
43
43
encoding = encoding || getDefaultEncoding ( ) ;
44
- data = toBuf ( data , encoding ) ;
45
- if ( ! isArrayBufferView ( data ) ) {
46
- throw new ERR_INVALID_ARG_TYPE (
47
- 'data' ,
48
- [ 'string' , 'Buffer' , 'TypedArray' , 'DataView' ] ,
49
- data
50
- ) ;
51
- }
44
+ data = checkIsArrayBufferView ( 'data' , toBuf ( data , encoding ) ) ;
52
45
this . _handle . update ( data ) ;
53
46
return this ;
54
47
} ;
@@ -84,14 +77,7 @@ Sign.prototype.sign = function sign(options, encoding) {
84
77
85
78
var pssSaltLength = getSaltLength ( options ) ;
86
79
87
- key = toBuf ( key ) ;
88
- if ( ! isArrayBufferView ( key ) ) {
89
- throw new ERR_INVALID_ARG_TYPE (
90
- 'key' ,
91
- [ 'string' , 'Buffer' , 'TypedArray' , 'DataView' ] ,
92
- key
93
- ) ;
94
- }
80
+ key = checkIsArrayBufferView ( 'key' , toBuf ( key ) ) ;
95
81
96
82
var ret = this . _handle . sign ( key , passphrase , rsaPadding , pssSaltLength ) ;
97
83
@@ -128,23 +114,10 @@ Verify.prototype.verify = function verify(options, signature, sigEncoding) {
128
114
129
115
var pssSaltLength = getSaltLength ( options ) ;
130
116
131
- key = toBuf ( key ) ;
132
- if ( ! isArrayBufferView ( key ) ) {
133
- throw new ERR_INVALID_ARG_TYPE (
134
- 'key' ,
135
- [ 'string' , 'Buffer' , 'TypedArray' , 'DataView' ] ,
136
- key
137
- ) ;
138
- }
117
+ key = checkIsArrayBufferView ( 'key' , toBuf ( key ) ) ;
139
118
140
- signature = toBuf ( signature , sigEncoding ) ;
141
- if ( ! isArrayBufferView ( signature ) ) {
142
- throw new ERR_INVALID_ARG_TYPE (
143
- 'signature' ,
144
- [ 'string' , 'Buffer' , 'TypedArray' , 'DataView' ] ,
145
- signature
146
- ) ;
147
- }
119
+ signature = checkIsArrayBufferView ( 'signature' ,
120
+ toBuf ( signature , sigEncoding ) ) ;
148
121
149
122
return this . _handle . verify ( key , signature , rsaPadding , pssSaltLength ) ;
150
123
} ;
0 commit comments