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