@@ -27,6 +27,8 @@ module.exports.genSaltSync = function genSaltSync(rounds) {
27
27
/// @param {Number } [rounds] number of rounds (default 10)
28
28
/// @param {Function } cb callback(err, salt)
29
29
module . exports . genSalt = function genSalt ( rounds , ignore , cb ) {
30
+ var error ;
31
+
30
32
// if callback is first argument, then use defaults for others
31
33
if ( typeof arguments [ 0 ] === 'function' ) {
32
34
// have to set callback first otherwise arguments are overriden
@@ -47,8 +49,9 @@ module.exports.genSalt = function genSalt(rounds, ignore, cb) {
47
49
rounds = 10 ;
48
50
} else if ( typeof rounds !== 'number' ) {
49
51
// callback error asynchronously
52
+ error = new Error ( 'rounds must be a number' ) ;
50
53
return process . nextTick ( function ( ) {
51
- cb ( new Error ( 'rounds must be a number' ) ) ;
54
+ cb ( error ) ;
52
55
} ) ;
53
56
}
54
57
@@ -87,15 +90,19 @@ module.exports.hashSync = function hashSync(data, salt) {
87
90
/// @param {String } salt the salt to use when hashing
88
91
/// @param {Function } cb callback(err, hash)
89
92
module . exports . hash = function hash ( data , salt , cb ) {
93
+ var error ;
94
+
90
95
if ( typeof data === 'function' ) {
96
+ error = new Error ( 'data must be a string and salt must either be a salt string or a number of rounds' ) ;
91
97
return process . nextTick ( function ( ) {
92
- data ( new Error ( 'data must be a string and salt must either be a salt string or a number of rounds' ) ) ;
98
+ data ( error ) ;
93
99
} ) ;
94
100
}
95
101
96
102
if ( typeof salt === 'function' ) {
103
+ error = new Error ( 'data must be a string and salt must either be a salt string or a number of rounds' ) ;
97
104
return process . nextTick ( function ( ) {
98
- salt ( new Error ( 'data must be a string and salt must either be a salt string or a number of rounds' ) ) ;
105
+ salt ( error ) ;
99
106
} ) ;
100
107
}
101
108
@@ -110,14 +117,16 @@ module.exports.hash = function hash(data, salt, cb) {
110
117
}
111
118
112
119
if ( data == null || salt == null ) {
120
+ error = new Error ( 'data and salt arguments required' ) ;
113
121
return process . nextTick ( function ( ) {
114
- cb ( new Error ( 'data and salt arguments required' ) ) ;
122
+ cb ( error ) ;
115
123
} ) ;
116
124
}
117
125
118
126
if ( typeof data !== 'string' || ( typeof salt !== 'string' && typeof salt !== 'number' ) ) {
127
+ error = new Error ( 'data must be a string and salt must either be a salt string or a number of rounds' ) ;
119
128
return process . nextTick ( function ( ) {
120
- cb ( new Error ( 'data must be a string and salt must either be a salt string or a number of rounds' ) ) ;
129
+ cb ( error ) ;
121
130
} ) ;
122
131
}
123
132
@@ -152,15 +161,19 @@ module.exports.compareSync = function compareSync(data, hash) {
152
161
/// @param {String } hash expected hash
153
162
/// @param {Function } cb callback(err, matched) - matched is true if hashed data matches hash
154
163
module . exports . compare = function compare ( data , hash , cb ) {
164
+ var error ;
165
+
155
166
if ( typeof data === 'function' ) {
167
+ error = new Error ( 'data and hash arguments required' ) ;
156
168
return process . nextTick ( function ( ) {
157
- data ( new Error ( 'data and hash arguments required' ) ) ;
169
+ data ( error ) ;
158
170
} ) ;
159
171
}
160
172
161
173
if ( typeof hash === 'function' ) {
174
+ error = new Error ( 'data and hash arguments required' ) ;
162
175
return process . nextTick ( function ( ) {
163
- hash ( new Error ( 'data and hash arguments required' ) ) ;
176
+ hash ( error ) ;
164
177
} ) ;
165
178
}
166
179
@@ -175,14 +188,16 @@ module.exports.compare = function compare(data, hash, cb) {
175
188
}
176
189
177
190
if ( data == null || hash == null ) {
191
+ error = new Error ( 'data and hash arguments required' ) ;
178
192
return process . nextTick ( function ( ) {
179
- cb ( new Error ( 'data and hash arguments required' ) ) ;
193
+ cb ( error ) ;
180
194
} ) ;
181
195
}
182
196
183
197
if ( typeof data !== 'string' || typeof hash !== 'string' ) {
198
+ error = new Error ( 'data and hash must be strings' ) ;
184
199
return process . nextTick ( function ( ) {
185
- cb ( new Error ( 'data and hash must be strings' ) ) ;
200
+ cb ( error ) ;
186
201
} ) ;
187
202
}
188
203
0 commit comments