PcapPlusPlus  Next
pcpp::internal::CryptoDataReader< CryptoDecoder > Class Template Reference

A template helper class for reading and decoding cryptographic data in different formats (DER/PEM) More...

#include <CryptoDataReader.h>

Static Public Member Functions

static std::unique_ptr< CryptoDecoder > fromDER (uint8_t *derData, size_t derDataLen, bool ownDerData=false)
 
static std::unique_ptr< CryptoDecoder > fromDER (const std::string &derData)
 
static std::unique_ptr< CryptoDecoder > fromDERFile (const std::string &derFileName)
 
static std::unique_ptr< CryptoDecoder > fromPEM (const std::string &pemData)
 
static std::unique_ptr< CryptoDecoder > fromPEMFile (const std::string &pemFileName)
 

Detailed Description

template<typename CryptoDecoder>
class pcpp::internal::CryptoDataReader< CryptoDecoder >

A template helper class for reading and decoding cryptographic data in different formats (DER/PEM)

Template Parameters
CryptoDecoderThe decoder type that will be used to process the cryptographic data. Must be a class that can be constructed with a byte array and a length, or a unique pointer to a byte array and a length

Member Function Documentation

◆ fromDER() [1/2]

template<typename CryptoDecoder >
static std::unique_ptr<CryptoDecoder> pcpp::internal::CryptoDataReader< CryptoDecoder >::fromDER ( const std::string &  derData)
inlinestatic

Creates a decoder from a hex string containing DER-encoded data

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

◆ fromDER() [2/2]

template<typename CryptoDecoder >
static std::unique_ptr<CryptoDecoder> pcpp::internal::CryptoDataReader< CryptoDecoder >::fromDER ( uint8_t *  derData,
size_t  derDataLen,
bool  ownDerData = false 
)
inlinestatic

Creates a decoder from DER-encoded data

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

◆ fromDERFile()

template<typename CryptoDecoder >
static std::unique_ptr<CryptoDecoder> pcpp::internal::CryptoDataReader< CryptoDecoder >::fromDERFile ( const std::string &  derFileName)
inlinestatic

Creates a decoder from a file containing DER-encoded data

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

◆ fromPEM()

template<typename CryptoDecoder >
static std::unique_ptr<CryptoDecoder> pcpp::internal::CryptoDataReader< CryptoDecoder >::fromPEM ( const std::string &  pemData)
inlinestatic

Creates a decoder from PEM-encoded data

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

◆ fromPEMFile()

template<typename CryptoDecoder >
static std::unique_ptr<CryptoDecoder> pcpp::internal::CryptoDataReader< CryptoDecoder >::fromPEMFile ( const std::string &  pemFileName)
inlinestatic

Creates a decoder from a file containing PEM-encoded data

Parameters
[in]pemFileNamePath to the file containing PEM-encoded data
Returns
A unique pointer to the created decoder
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 data