Skip to content

Commit a31e0e1

Browse files
committed
src: simplify X509Pointer/X509View pointer derefs a bit
1 parent 946c40a commit a31e0e1

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

deps/ncrypto/ncrypto.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ class X509View final {
570570
NCRYPTO_DISALLOW_MOVE(X509View)
571571

572572
inline X509* get() const { return const_cast<X509*>(cert_); }
573+
inline operator X509*() const { return const_cast<X509*>(cert_); }
574+
inline operator const X509*() const { return cert_; }
573575

574576
inline bool operator==(std::nullptr_t) noexcept { return cert_ == nullptr; }
575577
inline operator bool() const { return cert_ != nullptr; }
@@ -631,6 +633,8 @@ class X509Pointer final {
631633
inline bool operator==(std::nullptr_t) noexcept { return cert_ == nullptr; }
632634
inline operator bool() const { return cert_ != nullptr; }
633635
inline X509* get() const { return cert_.get(); }
636+
inline operator X509*() const { return cert_.get(); }
637+
inline operator const X509*() const { return cert_.get(); }
634638
void reset(X509* cert = nullptr);
635639
X509* release();
636640

src/crypto/crypto_common.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ bool UseSNIContext(
8383
STACK_OF(X509)* chain;
8484

8585
int err = SSL_CTX_get0_chain_certs(ctx, &chain);
86-
if (err == 1) err = SSL_use_certificate(ssl.get(), x509.get());
86+
if (err == 1) err = SSL_use_certificate(ssl.get(), x509);
8787
if (err == 1) err = SSL_use_PrivateKey(ssl.get(), pkey);
8888
if (err == 1 && chain != nullptr) err = SSL_set1_chain(ssl.get(), chain);
8989
return err == 1;

src/crypto/crypto_context.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,8 @@ void SecureContext::SetCACert(const BIOPointer& bio) {
787787
while (X509Pointer x509 = X509Pointer(PEM_read_bio_X509_AUX(
788788
bio.get(), nullptr, NoPasswordCallback, nullptr))) {
789789
CHECK_EQ(1,
790-
X509_STORE_add_cert(GetCertStoreOwnedByThisSecureContext(),
791-
x509.get()));
792-
CHECK_EQ(1, SSL_CTX_add_client_CA(ctx_.get(), x509.get()));
790+
X509_STORE_add_cert(GetCertStoreOwnedByThisSecureContext(), x509));
791+
CHECK_EQ(1, SSL_CTX_add_client_CA(ctx_.get(), x509));
793792
}
794793
}
795794

0 commit comments

Comments
 (0)