PcapPlusPlus  Next
pcpp::X509Certificate Class Reference

#include <X509Decoder.h>

Public Member Functions

X509Version getVersion () const
 
X509SerialNumber getSerialNumber () const
 
X509Name getIssuer () const
 
X509Name getSubject () const
 
X509Timestamp getNotBefore () const
 
X509Timestamp getNotAfter () const
 
X509Algorithm getPublicKeyAlgorithm () const
 
X509Key getPublicKey () const
 
X509Algorithm getSignatureAlgorithm () const
 
X509Key getSignature () const
 
const std::vector< X509Extension > & getExtensions () const
 
bool hasExtension (const X509ExtensionType &extensionType) const
 
const X509ExtensiongetExtension (X509ExtensionType extensionType) const
 
std::vector< uint8_t > toDER () const
 
std::string toPEM () const
 
std::string toJson (int indent=-1) const
 
const X509Internal::X509CertificategetRawCertificate () const
 

Static Public Member Functions

static std::unique_ptr< X509CertificatefromDER (uint8_t *derData, size_t derDataLen, bool ownDerData=false)
 
static std::unique_ptr< X509CertificatefromDER (const std::string &derData)
 
static std::unique_ptr< X509CertificatefromDERFile (const std::string &derFileName)
 
static std::unique_ptr< X509CertificatefromPEM (const std::string &pemData)
 
static std::unique_ptr< X509CertificatefromPEMFile (const std::string &pemFileName)
 

Detailed Description

Represents an X.509 certificate

Member Function Documentation

◆ fromDER() [1/2]

static std::unique_ptr<X509Certificate> pcpp::X509Certificate::fromDER ( const std::string &  derData)
static

Creates an X509Certificate from a hex string containing DER-encoded data

Parameters
[in]derDataHex string containing DER-encoded certificate data
Returns
A unique pointer to the created X509Certificate
Exceptions
Anexception if the data is not a valid ASN.1 record

◆ fromDER() [2/2]

static std::unique_ptr<X509Certificate> pcpp::X509Certificate::fromDER ( uint8_t *  derData,
size_t  derDataLen,
bool  ownDerData = false 
)
static

Creates an X509Certificate from DER-encoded data

Parameters
[in]derDataPointer to the DER-encoded certificate data
[in]derDataLenLength of the DER-encoded data
[in]ownDerDataIf true, the certificate will take ownership of the data and free it when the certificate class is destructed
Returns
A unique pointer to the created X509Certificate
Exceptions
Anexception if the data is not a valid ASN.1 record

◆ fromDERFile()

static std::unique_ptr<X509Certificate> pcpp::X509Certificate::fromDERFile ( const std::string &  derFileName)
static

Creates an X509Certificate from a file containing DER-encoded data

Parameters
[in]derFileNamePath to the file containing DER-encoded certificate
Returns
A unique pointer to the created X509Certificate
Exceptions
Anexception if the file doesn't exist, cannot be read or contains invalid data

◆ fromPEM()

static std::unique_ptr<X509Certificate> pcpp::X509Certificate::fromPEM ( const std::string &  pemData)
static

Creates an X509Certificate from PEM-encoded data

Parameters
[in]pemDataPEM-encoded certificate data
Returns
A unique pointer to the created X509Certificate
Exceptions
std::invalid_argumentexception if the data is not a valid PEM-encoded certificate

◆ fromPEMFile()

static std::unique_ptr<X509Certificate> pcpp::X509Certificate::fromPEMFile ( const std::string &  pemFileName)
static

Creates an X509Certificate from a file containing PEM-encoded data

Parameters
[in]pemFileNamePath to the file containing PEM-encoded certificate
Returns
A unique pointer to the created X509Certificate
Exceptions
std::runtime_errorexception if the file doesn't exist or cannot be read
std::invalid_argumentexception if the data is not a valid PEM-encoded certificate

◆ getExtension()

const X509Extension* pcpp::X509Certificate::getExtension ( X509ExtensionType  extensionType) const

Gets an extension by its type

Parameters
[in]extensionTypeThe type of extension to get
Returns
Pointer to the extension if found or nullptr otherwise

◆ getExtensions()

const std::vector<X509Extension>& pcpp::X509Certificate::getExtensions ( ) const

Gets the list of extensions in the certificate

Returns
A vector containing the certificate's extensions

◆ getIssuer()

X509Name pcpp::X509Certificate::getIssuer ( ) const

Gets the issuer of the certificate

Returns
The certificate's issuer name

◆ getNotAfter()

X509Timestamp pcpp::X509Certificate::getNotAfter ( ) const

Gets the notAfter timestamp of the certificate's validity period

Returns
The notAfter timestamp

◆ getNotBefore()

X509Timestamp pcpp::X509Certificate::getNotBefore ( ) const

Gets the notBefore timestamp of the certificate's validity period

Returns
The notBefore timestamp

◆ getPublicKey()

X509Key pcpp::X509Certificate::getPublicKey ( ) const

Gets the public key from the certificate

Returns
The public key

◆ getPublicKeyAlgorithm()

X509Algorithm pcpp::X509Certificate::getPublicKeyAlgorithm ( ) const

Gets the public key algorithm used in the certificate

Returns
The public key algorithm

◆ getRawCertificate()

const X509Internal::X509Certificate* pcpp::X509Certificate::getRawCertificate ( ) const

Gets the raw internal certificate object

Returns
Pointer to the internal X509Certificate implementation

◆ getSerialNumber()

X509SerialNumber pcpp::X509Certificate::getSerialNumber ( ) const

Gets the serial number of the certificate

Returns
The certificate's serial number

◆ getSignature()

X509Key pcpp::X509Certificate::getSignature ( ) const

Gets the signature of the certificate

Returns
The certificate's signature

◆ getSignatureAlgorithm()

X509Algorithm pcpp::X509Certificate::getSignatureAlgorithm ( ) const

Gets the signature algorithm used to sign the certificate

Returns
The signature algorithm

◆ getSubject()

X509Name pcpp::X509Certificate::getSubject ( ) const

Gets the subject of the certificate

Returns
The certificate's subject name

◆ getVersion()

X509Version pcpp::X509Certificate::getVersion ( ) const

Gets the version of the certificate

Returns
The X509Version of the certificate

◆ hasExtension()

bool pcpp::X509Certificate::hasExtension ( const X509ExtensionType extensionType) const

Checks if the certificate has a specific extension

Parameters
[in]extensionTypeThe extension type to check for
Returns
true if the extension is present, false otherwise

◆ toDER()

std::vector<uint8_t> pcpp::X509Certificate::toDER ( ) const

Converts the certificate to DER-encoded format

Returns
A byte vector containing the DER-encoded data

◆ toJson()

std::string pcpp::X509Certificate::toJson ( int  indent = -1) const

Converts the certificate to a JSON string representation

Parameters
[in]indentNumber of spaces to use for indentation (-1 for no pretty printing)
Returns
A JSON string representation of the certificate

◆ toPEM()

std::string pcpp::X509Certificate::toPEM ( ) const

Converts the certificate to PEM-encoded format

Returns
A string containing the PEM-encoded data