summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Makarenko <estliberitas@gmail.com>2016-02-23 15:43:32 +0300
committerBen Noordhuis <info@bnoordhuis.nl>2016-03-05 12:29:46 +0100
commita37401e0612578a76e6b148a798868ecbf62d9b7 (patch)
tree48b368fa51d957a85f697573af0d5d4bdc2adfa0 /src
parentc490b8ba54df6c730f7bfd02aaafe7c34f571f9e (diff)
downloadandroid-node-v8-a37401e0612578a76e6b148a798868ecbf62d9b7.tar.gz
android-node-v8-a37401e0612578a76e6b148a798868ecbf62d9b7.tar.bz2
android-node-v8-a37401e0612578a76e6b148a798868ecbf62d9b7.zip
crypto: simplify Certificate class bindings
Replace Certificate C++ class with simple functions. Update crypto.Certificate methods accordingly. PR-URL: https://github.com/nodejs/node/pull/5382 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src')
-rw-r--r--src/node_crypto.cc51
-rw-r--r--src/node_crypto.h23
2 files changed, 13 insertions, 61 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index ccaa2c7657..a62818942b 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -5484,29 +5484,7 @@ void GetCurves(const FunctionCallbackInfo<Value>& args) {
}
-void Certificate::Initialize(Environment* env, Local<Object> target) {
- HandleScope scope(env->isolate());
-
- Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
-
- t->InstanceTemplate()->SetInternalFieldCount(1);
-
- env->SetProtoMethod(t, "verifySpkac", VerifySpkac);
- env->SetProtoMethod(t, "exportPublicKey", ExportPublicKey);
- env->SetProtoMethod(t, "exportChallenge", ExportChallenge);
-
- target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Certificate"),
- t->GetFunction());
-}
-
-
-void Certificate::New(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args);
- new Certificate(env, args.This());
-}
-
-
-bool Certificate::VerifySpkac(const char* data, unsigned int len) {
+bool VerifySpkac(const char* data, unsigned int len) {
bool i = 0;
EVP_PKEY* pkey = nullptr;
NETSCAPE_SPKI* spki = nullptr;
@@ -5532,9 +5510,8 @@ bool Certificate::VerifySpkac(const char* data, unsigned int len) {
}
-void Certificate::VerifySpkac(const FunctionCallbackInfo<Value>& args) {
- Certificate* certificate = Unwrap<Certificate>(args.Holder());
- Environment* env = certificate->env();
+void VerifySpkac(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
bool i = false;
if (args.Length() < 1)
@@ -5549,13 +5526,13 @@ void Certificate::VerifySpkac(const FunctionCallbackInfo<Value>& args) {
char* data = Buffer::Data(args[0]);
CHECK_NE(data, nullptr);
- i = certificate->VerifySpkac(data, length);
+ i = VerifySpkac(data, length);
args.GetReturnValue().Set(i);
}
-const char* Certificate::ExportPublicKey(const char* data, int len) {
+const char* ExportPublicKey(const char* data, int len) {
char* buf = nullptr;
EVP_PKEY* pkey = nullptr;
NETSCAPE_SPKI* spki = nullptr;
@@ -5596,11 +5573,9 @@ const char* Certificate::ExportPublicKey(const char* data, int len) {
}
-void Certificate::ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
+void ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
- Certificate* certificate = Unwrap<Certificate>(args.Holder());
-
if (args.Length() < 1)
return env->ThrowTypeError("Missing argument");
@@ -5613,7 +5588,7 @@ void Certificate::ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
char* data = Buffer::Data(args[0]);
CHECK_NE(data, nullptr);
- const char* pkey = certificate->ExportPublicKey(data, length);
+ const char* pkey = ExportPublicKey(data, length);
if (pkey == nullptr)
return args.GetReturnValue().SetEmptyString();
@@ -5625,7 +5600,7 @@ void Certificate::ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
}
-const char* Certificate::ExportChallenge(const char* data, int len) {
+const char* ExportChallenge(const char* data, int len) {
NETSCAPE_SPKI* sp = nullptr;
sp = NETSCAPE_SPKI_b64_decode(data, len);
@@ -5641,11 +5616,9 @@ const char* Certificate::ExportChallenge(const char* data, int len) {
}
-void Certificate::ExportChallenge(const FunctionCallbackInfo<Value>& args) {
+void ExportChallenge(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
- Certificate* crt = Unwrap<Certificate>(args.Holder());
-
if (args.Length() < 1)
return env->ThrowTypeError("Missing argument");
@@ -5658,7 +5631,7 @@ void Certificate::ExportChallenge(const FunctionCallbackInfo<Value>& args) {
char* data = Buffer::Data(args[0]);
CHECK_NE(data, nullptr);
- const char* cert = crt->ExportChallenge(data, len);
+ const char* cert = ExportChallenge(data, len);
if (cert == nullptr)
return args.GetReturnValue().SetEmptyString();
@@ -5797,8 +5770,10 @@ void InitCrypto(Local<Object> target,
Hash::Initialize(env, target);
Sign::Initialize(env, target);
Verify::Initialize(env, target);
- Certificate::Initialize(env, target);
+ env->SetMethod(target, "certVerifySpkac", VerifySpkac);
+ env->SetMethod(target, "certExportPublicKey", ExportPublicKey);
+ env->SetMethod(target, "certExportChallenge", ExportChallenge);
#ifndef OPENSSL_NO_ENGINE
env->SetMethod(target, "setEngine", SetEngine);
#endif // !OPENSSL_NO_ENGINE
diff --git a/src/node_crypto.h b/src/node_crypto.h
index 8a6c667037..66c50efa2c 100644
--- a/src/node_crypto.h
+++ b/src/node_crypto.h
@@ -732,29 +732,6 @@ class ECDH : public BaseObject {
const EC_GROUP* group_;
};
-class Certificate : public AsyncWrap {
- public:
- static void Initialize(Environment* env, v8::Local<v8::Object> target);
-
- v8::Local<v8::Value> CertificateInit(const char* sign_type);
- bool VerifySpkac(const char* data, unsigned int len);
- const char* ExportPublicKey(const char* data, int len);
- const char* ExportChallenge(const char* data, int len);
-
- size_t self_size() const override { return sizeof(*this); }
-
- protected:
- static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
- static void VerifySpkac(const v8::FunctionCallbackInfo<v8::Value>& args);
- static void ExportPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
- static void ExportChallenge(const v8::FunctionCallbackInfo<v8::Value>& args);
-
- Certificate(Environment* env, v8::Local<v8::Object> wrap)
- : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CRYPTO) {
- MakeWeak<Certificate>(this);
- }
-};
-
bool EntropySource(unsigned char* buffer, size_t length);
#ifndef OPENSSL_NO_ENGINE
void SetEngine(const v8::FunctionCallbackInfo<v8::Value>& args);