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-11 16:05:38 +0300
committerAnna Henningsen <anna@addaleax.net>2020-06-22 21:50:36 +0300
commit7f185ec3c417f66ce485084d06084f1438faa5af (patch)
tree75c268c9740e4ecf5173cbf0e9d9d313b2ef76e8 /src/node_crypto.h
parent5489f19093e3f48b1d66bdb1bec61d6387c14d0f (diff)
src: store key data in separate class
This separates key handles from the actual key data: +-----------------+ | NativeKeyObject | +-----------------+ ^ extends | +-----------------+ +-----------------+ +---------------+ | KeyObject (JS) | -> | KeyObjectHandle | -> | KeyObjectData | +-----------------+ +-----------------+ +---------------+ 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.h')
-rw-r--r--src/node_crypto.h40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/node_crypto.h b/src/node_crypto.h
index f95ea64e973..9aaa188baa9 100644
--- a/src/node_crypto.h
+++ b/src/node_crypto.h
@@ -408,6 +408,27 @@ class ManagedEVPPKey {
EVPKeyPointer pkey_;
};
+class KeyObjectData {
+ public:
+ static KeyObjectData* CreateSecret(v8::Local<v8::ArrayBufferView> abv);
+ static KeyObjectData* CreateAsymmetric(KeyType type,
+ const ManagedEVPPKey& pkey);
+
+ KeyType GetKeyType() const;
+
+ // These functions allow unprotected access to the raw key material and should
+ // only be used to implement cryptograohic operations requiring the key.
+ ManagedEVPPKey GetAsymmetricKey() const;
+ const char* GetSymmetricKey() const;
+ size_t GetSymmetricKeySize() const;
+
+ private:
+ KeyType key_type_;
+ std::unique_ptr<char, std::function<void(char*)>> symmetric_key_;
+ unsigned int symmetric_key_len_;
+ ManagedEVPPKey asymmetric_key_;
+};
+
class KeyObjectHandle : public BaseObject {
public:
static v8::Local<v8::Function> Initialize(Environment* env,
@@ -422,21 +443,12 @@ class KeyObjectHandle : public BaseObject {
SET_MEMORY_INFO_NAME(KeyObjectHandle)
SET_SELF_SIZE(KeyObjectHandle)
- KeyType GetKeyType() const;
-
- // These functions allow unprotected access to the raw key material and should
- // only be used to implement cryptograohic operations requiring the key.
- ManagedEVPPKey GetAsymmetricKey() const;
- const char* GetSymmetricKey() const;
- size_t GetSymmetricKeySize() const;
+ const KeyObjectData* Data();
protected:
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Init(const v8::FunctionCallbackInfo<v8::Value>& args);
- void InitSecret(v8::Local<v8::ArrayBufferView> abv);
- void InitPublic(const ManagedEVPPKey& pkey);
- void InitPrivate(const ManagedEVPPKey& pkey);
static void GetAsymmetricKeyType(
const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -453,14 +465,10 @@ class KeyObjectHandle : public BaseObject {
const PrivateKeyEncodingConfig& config) const;
KeyObjectHandle(Environment* env,
- v8::Local<v8::Object> wrap,
- KeyType key_type);
+ v8::Local<v8::Object> wrap);
private:
- const KeyType key_type_;
- std::unique_ptr<char, std::function<void(char*)>> symmetric_key_;
- unsigned int symmetric_key_len_;
- ManagedEVPPKey asymmetric_key_;
+ std::unique_ptr<KeyObjectData> data_;
};
class NativeKeyObject : public BaseObject {