aboutsummaryrefslogtreecommitdiff
path: root/src/node_crypto.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_crypto.cc')
-rw-r--r--src/node_crypto.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 086216009c..0271383972 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -3330,6 +3330,8 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
t->InstanceTemplate()->SetInternalFieldCount(1);
env->SetProtoMethod(t, "init", Init);
+ env->SetProtoMethodNoSideEffect(t, "getAsymmetricKeySize",
+ GetAsymmetricKeySize);
env->SetProtoMethodNoSideEffect(t, "getSymmetricKeySize",
GetSymmetricKeySize);
env->SetProtoMethodNoSideEffect(t, "getAsymmetricKeyType",
@@ -3375,6 +3377,11 @@ const char* KeyObject::GetSymmetricKey() const {
return this->symmetric_key_.get();
}
+size_t KeyObject::GetAsymmetricKeySize() const {
+ CHECK_NE(key_type_, kKeyTypeSecret);
+ return EVP_PKEY_size(this->asymmetric_key_.get());
+}
+
size_t KeyObject::GetSymmetricKeySize() const {
CHECK_EQ(key_type_, kKeyTypeSecret);
return this->symmetric_key_len_;
@@ -3474,6 +3481,12 @@ void KeyObject::GetAsymmetricKeyType(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(key->GetAsymmetricKeyType());
}
+void KeyObject::GetAsymmetricKeySize(const FunctionCallbackInfo<Value>& args) {
+ KeyObject* key;
+ ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());
+ args.GetReturnValue().Set(static_cast<uint32_t>(key->GetAsymmetricKeySize()));
+}
+
void KeyObject::GetSymmetricKeySize(const FunctionCallbackInfo<Value>& args) {
KeyObject* key;
ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());