Skip to content

Commit 9ffaf76

Browse files
tniessentargos
authored andcommitted
src: use Maybe<void> in SecureContext
With recent versions of V8, it is not necessary to use Maybe<bool> anymore. This changes member functions of SecureContext to use Maybe<void> instead. PR-URL: #53883 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 87bab76 commit 9ffaf76

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/crypto/crypto_context.cc

+15-13
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ using v8::HandleScope;
3434
using v8::Int32;
3535
using v8::Integer;
3636
using v8::Isolate;
37-
using v8::Just;
37+
using v8::JustVoid;
3838
using v8::Local;
3939
using v8::Maybe;
4040
using v8::Nothing;
@@ -576,20 +576,20 @@ void SecureContext::SetKeylogCallback(KeylogCb cb) {
576576
SSL_CTX_set_keylog_callback(ctx_.get(), cb);
577577
}
578578

579-
Maybe<bool> SecureContext::UseKey(Environment* env,
579+
Maybe<void> SecureContext::UseKey(Environment* env,
580580
std::shared_ptr<KeyObjectData> key) {
581581
if (key->GetKeyType() != KeyType::kKeyTypePrivate) {
582582
THROW_ERR_CRYPTO_INVALID_KEYTYPE(env);
583-
return Nothing<bool>();
583+
return Nothing<void>();
584584
}
585585

586586
ClearErrorOnReturn clear_error_on_return;
587587
if (!SSL_CTX_use_PrivateKey(ctx_.get(), key->GetAsymmetricKey().get())) {
588588
ThrowCryptoError(env, ERR_get_error(), "SSL_CTX_use_PrivateKey");
589-
return Nothing<bool>();
589+
return Nothing<void>();
590590
}
591591

592-
return Just(true);
592+
return JustVoid();
593593
}
594594

595595
void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) {
@@ -689,9 +689,10 @@ void SecureContext::SetEngineKey(const FunctionCallbackInfo<Value>& args) {
689689
}
690690
#endif // !OPENSSL_NO_ENGINE
691691

692-
Maybe<bool> SecureContext::AddCert(Environment* env, BIOPointer&& bio) {
692+
Maybe<void> SecureContext::AddCert(Environment* env, BIOPointer&& bio) {
693693
ClearErrorOnReturn clear_error_on_return;
694-
if (!bio) return Just(false);
694+
// TODO(tniessen): this should be checked by the caller and not treated as ok
695+
if (!bio) return JustVoid();
695696
cert_.reset();
696697
issuer_.reset();
697698

@@ -701,9 +702,9 @@ Maybe<bool> SecureContext::AddCert(Environment* env, BIOPointer&& bio) {
701702
if (SSL_CTX_use_certificate_chain(
702703
ctx_.get(), std::move(bio), &cert_, &issuer_) == 0) {
703704
ThrowCryptoError(env, ERR_get_error(), "SSL_CTX_use_certificate_chain");
704-
return Nothing<bool>();
705+
return Nothing<void>();
705706
}
706-
return Just(true);
707+
return JustVoid();
707708
}
708709

709710
void SecureContext::SetCert(const FunctionCallbackInfo<Value>& args) {
@@ -745,16 +746,17 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
745746
sc->SetCACert(bio);
746747
}
747748

748-
Maybe<bool> SecureContext::SetCRL(Environment* env, const BIOPointer& bio) {
749+
Maybe<void> SecureContext::SetCRL(Environment* env, const BIOPointer& bio) {
749750
ClearErrorOnReturn clear_error_on_return;
750-
if (!bio) return Just(false);
751+
// TODO(tniessen): this should be checked by the caller and not treated as ok
752+
if (!bio) return JustVoid();
751753

752754
DeleteFnPtr<X509_CRL, X509_CRL_free> crl(
753755
PEM_read_bio_X509_CRL(bio.get(), nullptr, NoPasswordCallback, nullptr));
754756

755757
if (!crl) {
756758
THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Failed to parse CRL");
757-
return Nothing<bool>();
759+
return Nothing<void>();
758760
}
759761

760762
X509_STORE* cert_store = SSL_CTX_get_cert_store(ctx_.get());
@@ -767,7 +769,7 @@ Maybe<bool> SecureContext::SetCRL(Environment* env, const BIOPointer& bio) {
767769
CHECK_EQ(1,
768770
X509_STORE_set_flags(
769771
cert_store, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL));
770-
return Just(true);
772+
return JustVoid();
771773
}
772774

773775
void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {

src/crypto/crypto_context.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class SecureContext final : public BaseObject {
6060
inline const X509Pointer& issuer() const { return issuer_; }
6161
inline const X509Pointer& cert() const { return cert_; }
6262

63-
v8::Maybe<bool> AddCert(Environment* env, BIOPointer&& bio);
64-
v8::Maybe<bool> SetCRL(Environment* env, const BIOPointer& bio);
65-
v8::Maybe<bool> UseKey(Environment* env, std::shared_ptr<KeyObjectData> key);
63+
v8::Maybe<void> AddCert(Environment* env, BIOPointer&& bio);
64+
v8::Maybe<void> SetCRL(Environment* env, const BIOPointer& bio);
65+
v8::Maybe<void> UseKey(Environment* env, std::shared_ptr<KeyObjectData> key);
6666

6767
void SetCACert(const BIOPointer& bio);
6868
void SetRootCerts();

0 commit comments

Comments
 (0)