@@ -203,97 +203,62 @@ void X509Certificate::Parse(const FunctionCallbackInfo<Value>& args) {
203
203
args.GetReturnValue ().Set (cert);
204
204
}
205
205
206
- void X509Certificate::Subject (const FunctionCallbackInfo<Value>& args) {
206
+ template <MaybeLocal<Value> Property (
207
+ Environment* env, X509* cert, const BIOPointer& bio)>
208
+ static void ReturnPropertyThroughBIO(const FunctionCallbackInfo<Value>& args) {
207
209
Environment* env = Environment::GetCurrent (args);
208
210
X509Certificate* cert;
209
211
ASSIGN_OR_RETURN_UNWRAP (&cert, args.Holder ());
210
212
BIOPointer bio (BIO_new (BIO_s_mem ()));
211
213
CHECK (bio);
212
214
Local<Value> ret;
213
- if (GetSubject (env, bio, cert->get ()).ToLocal (&ret))
215
+ if (Property (env, cert->get (), bio ).ToLocal (&ret))
214
216
args.GetReturnValue ().Set (ret);
215
217
}
216
218
219
+ void X509Certificate::Subject (const FunctionCallbackInfo<Value>& args) {
220
+ ReturnPropertyThroughBIO<GetSubject>(args);
221
+ }
222
+
217
223
void X509Certificate::Issuer (const FunctionCallbackInfo<Value>& args) {
218
- Environment* env = Environment::GetCurrent (args);
219
- X509Certificate* cert;
220
- ASSIGN_OR_RETURN_UNWRAP (&cert, args.Holder ());
221
- BIOPointer bio (BIO_new (BIO_s_mem ()));
222
- CHECK (bio);
223
- Local<Value> ret;
224
- if (GetIssuerString (env, bio, cert->get ()).ToLocal (&ret))
225
- args.GetReturnValue ().Set (ret);
224
+ ReturnPropertyThroughBIO<GetIssuerString>(args);
226
225
}
227
226
228
227
void X509Certificate::SubjectAltName (const FunctionCallbackInfo<Value>& args) {
229
- Environment* env = Environment::GetCurrent (args);
230
- X509Certificate* cert;
231
- ASSIGN_OR_RETURN_UNWRAP (&cert, args.Holder ());
232
- BIOPointer bio (BIO_new (BIO_s_mem ()));
233
- CHECK (bio);
234
- Local<Value> ret;
235
- if (GetSubjectAltNameString (env, bio, cert->get ()).ToLocal (&ret))
236
- args.GetReturnValue ().Set (ret);
228
+ ReturnPropertyThroughBIO<GetSubjectAltNameString>(args);
237
229
}
238
230
239
231
void X509Certificate::InfoAccess (const FunctionCallbackInfo<Value>& args) {
240
- Environment* env = Environment::GetCurrent (args);
241
- X509Certificate* cert;
242
- ASSIGN_OR_RETURN_UNWRAP (&cert, args.Holder ());
243
- BIOPointer bio (BIO_new (BIO_s_mem ()));
244
- CHECK (bio);
245
- Local<Value> ret;
246
- if (GetInfoAccessString (env, bio, cert->get ()).ToLocal (&ret))
247
- args.GetReturnValue ().Set (ret);
232
+ ReturnPropertyThroughBIO<GetInfoAccessString>(args);
248
233
}
249
234
250
235
void X509Certificate::ValidFrom (const FunctionCallbackInfo<Value>& args) {
251
- Environment* env = Environment::GetCurrent (args);
252
- X509Certificate* cert;
253
- ASSIGN_OR_RETURN_UNWRAP (&cert, args.Holder ());
254
- BIOPointer bio (BIO_new (BIO_s_mem ()));
255
- CHECK (bio);
256
- Local<Value> ret;
257
- if (GetValidFrom (env, cert->get (), bio).ToLocal (&ret))
258
- args.GetReturnValue ().Set (ret);
236
+ ReturnPropertyThroughBIO<GetValidFrom>(args);
259
237
}
260
238
261
239
void X509Certificate::ValidTo (const FunctionCallbackInfo<Value>& args) {
240
+ ReturnPropertyThroughBIO<GetValidTo>(args);
241
+ }
242
+
243
+ template <MaybeLocal<Value> Property (Environment* env, X509* cert)>
244
+ static void ReturnProperty(const FunctionCallbackInfo<Value>& args) {
262
245
Environment* env = Environment::GetCurrent (args);
263
246
X509Certificate* cert;
264
247
ASSIGN_OR_RETURN_UNWRAP (&cert, args.Holder ());
265
- BIOPointer bio (BIO_new (BIO_s_mem ()));
266
- CHECK (bio);
267
248
Local<Value> ret;
268
- if (GetValidTo (env, cert->get (), bio).ToLocal (&ret))
269
- args.GetReturnValue ().Set (ret);
249
+ if (Property (env, cert->get ()).ToLocal (&ret)) args.GetReturnValue ().Set (ret);
270
250
}
271
251
272
252
void X509Certificate::KeyUsage (const FunctionCallbackInfo<Value>& args) {
273
- Environment* env = Environment::GetCurrent (args);
274
- X509Certificate* cert;
275
- ASSIGN_OR_RETURN_UNWRAP (&cert, args.Holder ());
276
- Local<Value> ret;
277
- if (GetKeyUsage (env, cert->get ()).ToLocal (&ret))
278
- args.GetReturnValue ().Set (ret);
253
+ ReturnProperty<GetKeyUsage>(args);
279
254
}
280
255
281
256
void X509Certificate::SerialNumber (const FunctionCallbackInfo<Value>& args) {
282
- Environment* env = Environment::GetCurrent (args);
283
- X509Certificate* cert;
284
- ASSIGN_OR_RETURN_UNWRAP (&cert, args.Holder ());
285
- Local<Value> ret;
286
- if (GetSerialNumber (env, cert->get ()).ToLocal (&ret))
287
- args.GetReturnValue ().Set (ret);
257
+ ReturnProperty<GetSerialNumber>(args);
288
258
}
289
259
290
260
void X509Certificate::Raw (const FunctionCallbackInfo<Value>& args) {
291
- Environment* env = Environment::GetCurrent (args);
292
- X509Certificate* cert;
293
- ASSIGN_OR_RETURN_UNWRAP (&cert, args.Holder ());
294
- Local<Value> ret;
295
- if (GetRawDERCertificate (env, cert->get ()).ToLocal (&ret))
296
- args.GetReturnValue ().Set (ret);
261
+ ReturnProperty<GetRawDERCertificate>(args);
297
262
}
298
263
299
264
void X509Certificate::PublicKey (const FunctionCallbackInfo<Value>& args) {
0 commit comments