Botan 3.6.1
Crypto and TLS for C&
Botan::Path_Validation_Result Class Referencefinal

#include <x509path.h>

Public Types

typedef Certificate_Status_Code Code
 

Public Member Functions

const CertificatePathStatusCodesall_statuses () const
 
const std::vector< X509_Certificate > & cert_path () const
 
bool no_warnings () const
 
 Path_Validation_Result (Certificate_Status_Code status)
 
 Path_Validation_Result (CertificatePathStatusCodes status, std::vector< X509_Certificate > &&cert_chain)
 
Certificate_Status_Code result () const
 
std::string result_string () const
 
bool successful_validation () const
 
const X509_Certificatetrust_root () const
 
CertificatePathStatusCodes warnings () const
 
std::string warnings_string () const
 

Static Public Member Functions

static const char * status_string (Certificate_Status_Code code)
 

Detailed Description

Represents the result of a PKIX path validation

Definition at line 157 of file x509path.h.

Member Typedef Documentation

◆ Code

Constructor & Destructor Documentation

◆ Path_Validation_Result() [1/2]

Botan::Path_Validation_Result::Path_Validation_Result ( CertificatePathStatusCodes status,
std::vector< X509_Certificate > && cert_chain )

Create a Path_Validation_Result

Parameters
statuslist of validation status codes
cert_chainthe certificate chain that was validated

Definition at line 1028 of file x509path.cpp.

1029 :
1030 m_all_status(std::move(status)),
1031 m_warnings(find_warnings(m_all_status)),
1032 m_cert_path(std::move(cert_chain)),
1033 m_overall(PKIX::overall_status(m_all_status)) {}
Certificate_Status_Code overall_status(const CertificatePathStatusCodes &cert_status)
Definition x509path.cpp:862

◆ Path_Validation_Result() [2/2]

Botan::Path_Validation_Result::Path_Validation_Result ( Certificate_Status_Code status)
inlineexplicit

Create a Path_Validation_Result

Parameters
statusvalidation status code

Definition at line 225 of file x509path.h.

225: m_overall(status) {}

Member Function Documentation

◆ all_statuses()

const CertificatePathStatusCodes & Botan::Path_Validation_Result::all_statuses ( ) const
inline
Returns
a set of status codes for each certificate in the chain

Definition at line 191 of file x509path.h.

191{ return m_all_status; }

◆ cert_path()

const std::vector< X509_Certificate > & Botan::Path_Validation_Result::cert_path ( ) const
inline
Returns
the full path from subject to trust root This path may be empty

Definition at line 171 of file x509path.h.

171{ return m_cert_path; }

◆ no_warnings()

bool Botan::Path_Validation_Result::no_warnings ( ) const
Returns
true iff no warnings occured during validation

Definition at line 1051 of file x509path.cpp.

1051 {
1052 for(const auto& status_set_i : m_warnings) {
1053 if(!status_set_i.empty()) {
1054 return false;
1055 }
1056 }
1057 return true;
1058}

◆ result()

Certificate_Status_Code Botan::Path_Validation_Result::result ( ) const
inline
Returns
overall validation result code

Definition at line 186 of file x509path.h.

186{ return m_overall; }

Referenced by result_string(), successful_validation(), and trust_root().

◆ result_string()

std::string Botan::Path_Validation_Result::result_string ( ) const
Returns
string representation of the validation result

Definition at line 1064 of file x509path.cpp.

1064 {
1065 return status_string(result());
1066}
Certificate_Status_Code result() const
Definition x509path.h:186
static const char * status_string(Certificate_Status_Code code)

References result(), and status_string().

Referenced by Botan::TLS::Callbacks::tls_verify_cert_chain().

◆ status_string()

const char * Botan::Path_Validation_Result::status_string ( Certificate_Status_Code code)
static
Parameters
codevalidation status code
Returns
corresponding validation status message

Definition at line 1068 of file x509path.cpp.

1068 {
1069 if(const char* s = to_string(code)) {
1070 return s;
1071 }
1072
1073 return "Unknown error";
1074}
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13

References Botan::to_string().

Referenced by result_string(), and warnings_string().

◆ successful_validation()

bool Botan::Path_Validation_Result::successful_validation ( ) const

◆ trust_root()

const X509_Certificate & Botan::Path_Validation_Result::trust_root ( ) const
Returns
the trust root of the validation if successful throws an exception if the validation failed

Definition at line 1035 of file x509path.cpp.

1035 {
1036 if(m_cert_path.empty()) {
1037 throw Invalid_State("Path_Validation_Result::trust_root no path set");
1038 }
1040 throw Invalid_State("Path_Validation_Result::trust_root meaningless with invalid status");
1041 }
1042
1043 return m_cert_path[m_cert_path.size() - 1];
1044}

References result(), and Botan::VERIFIED.

◆ warnings()

CertificatePathStatusCodes Botan::Path_Validation_Result::warnings ( ) const
Returns
the subset of status codes that are warnings

Definition at line 1060 of file x509path.cpp.

1060 {
1061 return m_warnings;
1062}

◆ warnings_string()

std::string Botan::Path_Validation_Result::warnings_string ( ) const
Returns
string representation of the warnings

Definition at line 1076 of file x509path.cpp.

1076 {
1077 const std::string sep(", ");
1078 std::ostringstream oss;
1079 for(size_t i = 0; i < m_warnings.size(); i++) {
1080 for(auto code : m_warnings[i]) {
1081 oss << "[" << std::to_string(i) << "] " << status_string(code) << sep;
1082 }
1083 }
1084
1085 std::string res = oss.str();
1086 // remove last sep
1087 if(res.size() >= sep.size()) {
1088 res = res.substr(0, res.size() - sep.size());
1089 }
1090 return res;
1091}

References status_string().


The documentation for this class was generated from the following files: