summaryrefslogtreecommitdiff
path: root/src/node_crypto.cc
diff options
context:
space:
mode:
authorPatrick Gansterer <paroga@paroga.com>2019-03-02 01:34:11 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-07 00:24:07 +0100
commit4895927a0a4372e0699f84657e0a299393a3d281 (patch)
treecf20299808c5833ea4c70c3c54e5eb302790bb29 /src/node_crypto.cc
parent53d4e04be59bdc34ea0d8db994e7607b8af7d790 (diff)
downloadandroid-node-v8-4895927a0a4372e0699f84657e0a299393a3d281.tar.gz
android-node-v8-4895927a0a4372e0699f84657e0a299393a3d281.tar.bz2
android-node-v8-4895927a0a4372e0699f84657e0a299393a3d281.zip
crypto: add KeyObject.asymmetricKeySize
Expose the size of asymetric keys of crypto key object from the crypto module added in v11.6.0. PR-URL: https://github.com/nodejs/node/pull/26387 Refs: https://github.com/nodejs/node/pull/24234 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
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());