Skip to content

Commit

Permalink
src: simplify X509Pointer/X509View pointer derefs a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Dec 31, 2024
1 parent 946c40a commit a31e0e1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions deps/ncrypto/ncrypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ class X509View final {
NCRYPTO_DISALLOW_MOVE(X509View)

inline X509* get() const { return const_cast<X509*>(cert_); }
inline operator X509*() const { return const_cast<X509*>(cert_); }
inline operator const X509*() const { return cert_; }

inline bool operator==(std::nullptr_t) noexcept { return cert_ == nullptr; }
inline operator bool() const { return cert_ != nullptr; }
Expand Down Expand Up @@ -631,6 +633,8 @@ class X509Pointer final {
inline bool operator==(std::nullptr_t) noexcept { return cert_ == nullptr; }
inline operator bool() const { return cert_ != nullptr; }
inline X509* get() const { return cert_.get(); }
inline operator X509*() const { return cert_.get(); }
inline operator const X509*() const { return cert_.get(); }
void reset(X509* cert = nullptr);
X509* release();

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool UseSNIContext(
STACK_OF(X509)* chain;

int err = SSL_CTX_get0_chain_certs(ctx, &chain);
if (err == 1) err = SSL_use_certificate(ssl.get(), x509.get());
if (err == 1) err = SSL_use_certificate(ssl.get(), x509);
if (err == 1) err = SSL_use_PrivateKey(ssl.get(), pkey);
if (err == 1 && chain != nullptr) err = SSL_set1_chain(ssl.get(), chain);
return err == 1;
Expand Down
5 changes: 2 additions & 3 deletions src/crypto/crypto_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,8 @@ void SecureContext::SetCACert(const BIOPointer& bio) {
while (X509Pointer x509 = X509Pointer(PEM_read_bio_X509_AUX(
bio.get(), nullptr, NoPasswordCallback, nullptr))) {
CHECK_EQ(1,
X509_STORE_add_cert(GetCertStoreOwnedByThisSecureContext(),
x509.get()));
CHECK_EQ(1, SSL_CTX_add_client_CA(ctx_.get(), x509.get()));
X509_STORE_add_cert(GetCertStoreOwnedByThisSecureContext(), x509));
CHECK_EQ(1, SSL_CTX_add_client_CA(ctx_.get(), x509));
}
}

Expand Down

0 comments on commit a31e0e1

Please sign in to comment.