diff --git a/include/opendht/crypto.h b/include/opendht/crypto.h index c019096f..6ef87057 100644 --- a/include/opendht/crypto.h +++ b/include/opendht/crypto.h @@ -185,9 +185,10 @@ struct Certificate : public Serializable { std::string getIssuerUID() const; /** - * PEM encoded certificate + * PEM encoded certificate. + * If chain is true, the issuer chain will be included (default). */ - std::string toString() const; + std::string toString(bool chain = true) const; gnutls_x509_crt_t cert {}; std::shared_ptr issuer {}; diff --git a/src/crypto.cpp b/src/crypto.cpp index 93284367..3dc42e2f 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -447,7 +447,7 @@ Certificate::getIssuerUID() const } std::string -Certificate::toString() const +Certificate::toString(bool chain) const { std::ostringstream ss; const Certificate* crt = this; @@ -461,6 +461,8 @@ Certificate::toString() const } str.resize(buf_sz); ss << str; + if (not chain) + break; crt = crt->issuer.get(); } return ss.str();