Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2020-05-10 21:09:18 +0300
committerAnna Henningsen <anna@addaleax.net>2020-06-22 21:50:34 +0300
commit5489f19093e3f48b1d66bdb1bec61d6387c14d0f (patch)
tree3949f36c297f62a96c3b93fb15faca60b2f186f8 /src/node_crypto.cc
parent1e27e0a4db7f26bbfbe4f9902fe33d1145b0ac11 (diff)
src: add NativeKeyObject base class
+---------------------+ | BaseObject | +---------------------+ | | | +---------------------+ | NativeKeyObject | +---------------------+ | | | +---------------------+ | KeyObject | +---------------------+ / \ / \ / \ / \ +---------------------+ +---------------------+ | SecretKeyObject | | AsymmetricKeyObject | +---------------------+ +---------------------+ / \ / \ / \ / \ +---------------------+ +---------------------+ | PublicKeyObject | | PrivateKeyObject | +---------------------+ +---------------------+ PR-URL: https://github.com/nodejs/node/pull/33360 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_crypto.cc')
-rw-r--r--src/node_crypto.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 6967f1719d2..42cfe138c32 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -3468,6 +3468,31 @@ MaybeLocal<Value> KeyObjectHandle::ExportPrivateKey(
return WritePrivateKey(env(), asymmetric_key_.get(), config);
}
+void NativeKeyObject::New(const FunctionCallbackInfo<Value>& args) {
+ CHECK_EQ(args.Length(), 0);
+}
+
+static void CreateNativeKeyObjectClass(
+ const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+
+ CHECK_EQ(args.Length(), 1);
+ Local<Value> callback = args[0];
+ CHECK(callback->IsFunction());
+
+ Local<FunctionTemplate> t = env->NewFunctionTemplate(NativeKeyObject::New);
+ t->InstanceTemplate()->SetInternalFieldCount(
+ KeyObjectHandle::kInternalFieldCount);
+
+ Local<Value> ctor = t->GetFunction(env->context()).ToLocalChecked();
+
+ Local<Value> recv = Undefined(env->isolate());
+ Local<Value> ret =
+ callback.As<Function>()->Call(env->context(), recv, 1, &ctor)
+ .ToLocalChecked();
+ args.GetReturnValue().Set(ret);
+}
+
CipherBase::CipherBase(Environment* env,
Local<Object> wrap,
CipherKind kind)
@@ -6871,6 +6896,8 @@ void Initialize(Local<Object> target,
SecureContext::Initialize(env, target);
env->set_crypto_key_object_handle_constructor(
KeyObjectHandle::Initialize(env, target));
+ env->SetMethod(target, "createNativeKeyObjectClass",
+ CreateNativeKeyObjectClass);
CipherBase::Initialize(env, target);
DiffieHellman::Initialize(env, target);
ECDH::Initialize(env, target);