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:
authorDaniel Bevenius <daniel.bevenius@gmail.com>2020-07-03 14:24:11 +0300
committerDaniel Bevenius <daniel.bevenius@gmail.com>2020-07-07 07:10:12 +0300
commit30612316e4af64e530b9b3ecc1cbfc98d11cae3e (patch)
tree7e53e59a8aa9f927ef99881fbb21712b921071cc /src/node_crypto.cc
parent772fdb0cd3163ad9299cdb1168b10059abe6ee71 (diff)
src: add encoding_type variable in WritePrivateKey
This commit adds a local variable named encoding_type which is set to the value of the Maybe using ToChecked(). The motivation for this is the code for ToChecked() could be executed multiple times depending on path taken at runtime. I also think this improves readability, or at least it is as readable as before this change. PR-URL: https://github.com/nodejs/node/pull/34181 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'src/node_crypto.cc')
-rw-r--r--src/node_crypto.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index aace8e2c05e..eae0f2e49d3 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -3151,7 +3151,8 @@ static MaybeLocal<Value> WritePrivateKey(
bool err;
- if (config.type_.ToChecked() == kKeyEncodingPKCS1) {
+ PKEncodingType encoding_type = config.type_.ToChecked();
+ if (encoding_type == kKeyEncodingPKCS1) {
// PKCS#1 is only permitted for RSA keys.
CHECK_EQ(EVP_PKEY_id(pkey), EVP_PKEY_RSA);
@@ -3171,7 +3172,7 @@ static MaybeLocal<Value> WritePrivateKey(
CHECK_NULL(config.cipher_);
err = i2d_RSAPrivateKey_bio(bio.get(), rsa.get()) != 1;
}
- } else if (config.type_.ToChecked() == kKeyEncodingPKCS8) {
+ } else if (encoding_type == kKeyEncodingPKCS8) {
if (config.format_ == kKeyFormatPEM) {
// Encode PKCS#8 as PEM.
err = PEM_write_bio_PKCS8PrivateKey(
@@ -3191,7 +3192,7 @@ static MaybeLocal<Value> WritePrivateKey(
nullptr, nullptr) != 1;
}
} else {
- CHECK_EQ(config.type_.ToChecked(), kKeyEncodingSEC1);
+ CHECK_EQ(encoding_type, kKeyEncodingSEC1);
// SEC1 is only permitted for EC keys.
CHECK_EQ(EVP_PKEY_id(pkey), EVP_PKEY_EC);