| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 010d2ec commit 786a1c5
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,6 +51,18 @@ void ManagedX509::MemoryInfo(MemoryTracker* tracker) const { | |||
| 51 | 51 | tracker->TrackFieldWithSize("cert", size); | |
| 52 | 52 | } | |
| 53 | 53 | ||
| 54 | + namespace { | ||
| 55 | + template <const EVP_MD* (*algo)()> | ||
| 56 | + void Fingerprint(const FunctionCallbackInfo<Value>& args) { | ||
| 57 | + Environment* env = Environment::GetCurrent(args); | ||
| 58 | + X509Certificate* cert; | ||
| 59 | + ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder()); | ||
| 60 | + Local<Value> ret; | ||
| 61 | + if (GetFingerprintDigest(env, algo(), cert->get()).ToLocal(&ret)) | ||
| 62 | + args.GetReturnValue().Set(ret); | ||
| 63 | + } | ||
| 64 | + } // namespace | ||
| 65 | + | ||
| 54 | 66 | Local<FunctionTemplate> X509Certificate::GetConstructorTemplate( | |
| 55 | 67 | Environment* env) { | |
| 56 | 68 | Local<FunctionTemplate> tmpl = env->x509_constructor_template(); | |
@@ -67,9 +79,9 @@ Local<FunctionTemplate> X509Certificate::GetConstructorTemplate( | |||
| 67 | 79 | SetProtoMethod(isolate, tmpl, "issuer", Issuer); | |
| 68 | 80 | SetProtoMethod(isolate, tmpl, "validTo", ValidTo); | |
| 69 | 81 | SetProtoMethod(isolate, tmpl, "validFrom", ValidFrom); | |
| 70 | - SetProtoMethod(isolate, tmpl, "fingerprint", Fingerprint); | ||
| 71 | - SetProtoMethod(isolate, tmpl, "fingerprint256", Fingerprint256); | ||
| 72 | - SetProtoMethod(isolate, tmpl, "fingerprint512", Fingerprint512); | ||
| 82 | + SetProtoMethod(isolate, tmpl, "fingerprint", Fingerprint<EVP_sha1>); | ||
| 83 | + SetProtoMethod(isolate, tmpl, "fingerprint256", Fingerprint<EVP_sha256>); | ||
| 84 | + SetProtoMethod(isolate, tmpl, "fingerprint512", Fingerprint<EVP_sha512>); | ||
| 73 | 85 | SetProtoMethod(isolate, tmpl, "keyUsage", KeyUsage); | |
| 74 | 86 | SetProtoMethod(isolate, tmpl, "serialNumber", SerialNumber); | |
| 75 | 87 | SetProtoMethod(isolate, tmpl, "pem", Pem); | |
@@ -257,33 +269,6 @@ void X509Certificate::ValidTo(const FunctionCallbackInfo<Value>& args) { | |||
| 257 | 269 | args.GetReturnValue().Set(ret); | |
| 258 | 270 | } | |
| 259 | 271 | ||
| 260 | - void X509Certificate::Fingerprint(const FunctionCallbackInfo<Value>& args) { | ||
| 261 | - Environment* env = Environment::GetCurrent(args); | ||
| 262 | - X509Certificate* cert; | ||
| 263 | - ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder()); | ||
| 264 | - Local<Value> ret; | ||
| 265 | - if (GetFingerprintDigest(env, EVP_sha1(), cert->get()).ToLocal(&ret)) | ||
| 266 | - args.GetReturnValue().Set(ret); | ||
| 267 | - } | ||
| 268 | - | ||
| 269 | - void X509Certificate::Fingerprint256(const FunctionCallbackInfo<Value>& args) { | ||
| 270 | - Environment* env = Environment::GetCurrent(args); | ||
| 271 | - X509Certificate* cert; | ||
| 272 | - ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder()); | ||
| 273 | - Local<Value> ret; | ||
| 274 | - if (GetFingerprintDigest(env, EVP_sha256(), cert->get()).ToLocal(&ret)) | ||
| 275 | - args.GetReturnValue().Set(ret); | ||
| 276 | - } | ||
| 277 | - | ||
| 278 | - void X509Certificate::Fingerprint512(const FunctionCallbackInfo<Value>& args) { | ||
| 279 | - Environment* env = Environment::GetCurrent(args); | ||
| 280 | - X509Certificate* cert; | ||
| 281 | - ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder()); | ||
| 282 | - Local<Value> ret; | ||
| 283 | - if (GetFingerprintDigest(env, EVP_sha512(), cert->get()).ToLocal(&ret)) | ||
| 284 | - args.GetReturnValue().Set(ret); | ||
| 285 | - } | ||
| 286 | - | ||
| 287 | 272 | void X509Certificate::KeyUsage(const FunctionCallbackInfo<Value>& args) { | |
| 288 | 273 | Environment* env = Environment::GetCurrent(args); | |
| 289 | 274 | X509Certificate* cert; | |
@@ -570,9 +555,9 @@ void X509Certificate::RegisterExternalReferences( | |||
| 570 | 555 | registry->Register(Issuer); | |
| 571 | 556 | registry->Register(ValidTo); | |
| 572 | 557 | registry->Register(ValidFrom); | |
| 573 | - registry->Register(Fingerprint); | ||
| 574 | - registry->Register(Fingerprint256); | ||
| 575 | - registry->Register(Fingerprint512); | ||
| 558 | + registry->Register(Fingerprint<EVP_sha1>); | ||
| 559 | + registry->Register(Fingerprint<EVP_sha256>); | ||
| 560 | + registry->Register(Fingerprint<EVP_sha512>); | ||
| 576 | 561 | registry->Register(KeyUsage); | |
| 577 | 562 | registry->Register(SerialNumber); | |
| 578 | 563 | registry->Register(Pem); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,9 +79,6 @@ class X509Certificate : public BaseObject { | |||
| 79 | 79 | static void InfoAccess(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 80 | 80 | static void ValidFrom(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 81 | 81 | static void ValidTo(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 82 | - static void Fingerprint(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 83 | - static void Fingerprint256(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 84 | - static void Fingerprint512(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 85 | 82 | static void KeyUsage(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 86 | 83 | static void SerialNumber(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 87 | 84 | static void Raw(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments