PcapPlusPlus  Next
pcpp::SSLExtension Class Reference

#include <SSLHandshake.h>

Inheritance diagram for pcpp::SSLExtension:
pcpp::SSLServerNameIndicationExtension pcpp::SSLSupportedVersionsExtension pcpp::TLSECPointFormatExtension pcpp::TLSSupportedGroupsExtension

Classes

struct  SSLExtensionStruct
 

Public Member Functions

 SSLExtension (uint8_t *data)
 
 SSLExtension (uint8_t *data, size_t dataLen)
 Constructs an SSLExtension that interprets the provided data as the raw bytes of the extension. More...
 
SSLExtensionType getType () const
 
uint16_t getTypeAsInt () const
 
uint16_t getLength () const
 
uint16_t getTotalLength () const
 
uint8_t * getData () const
 

Static Public Member Functions

template<typename T , typename std::enable_if_t< std::is_base_of< SSLExtension, T >::value, bool > = true>
static std::unique_ptr< T > tryCreateExtension (uint8_t *data, size_t dataLen)
 A static method that tries to create an instance of a specific extension type. More...
 

Detailed Description

Represents a SSL/TLS extension. This is a base class that can represent any type of extension. Inherited classes may contain parsing logic for specific extensions. This class provides capabilities such as getting the extension type, length and viewing the extension data as raw (byte array)

Constructor & Destructor Documentation

◆ SSLExtension() [1/2]

pcpp::SSLExtension::SSLExtension ( uint8_t *  data)
explicit

C'tor for this class

Parameters
[in]dataThe raw data for the extension
Deprecated:
This constructor is deprecated because it uses an unbound memory span. Use the constructor with bounded span.

◆ SSLExtension() [2/2]

pcpp::SSLExtension::SSLExtension ( uint8_t *  data,
size_t  dataLen 
)

Constructs an SSLExtension that interprets the provided data as the raw bytes of the extension.

The memory span defined by data and dataLen can be larger than the actual extension data. If so, only the bytes corresponding to the extension header (type and length fields) + [length] bytes of extension data will be parsed. The rest of the span will be ignored.

The above behaviour allows variable length extensions to be parsed, as SSL extensions are laid out sequentially in memory on a payload.

Parameters
[in]dataThe raw data for the extension.
[in]dataLenThe length of the data in bytes.
Exceptions
std::invalid_argumentif data is nullptr or if dataLen is smaller than the size of the extension header (type and length fields).

Member Function Documentation

◆ getData()

uint8_t* pcpp::SSLExtension::getData ( ) const
Returns
A pointer to the raw data of the extension

◆ getLength()

uint16_t pcpp::SSLExtension::getLength ( ) const
Returns
The length of the extension data in bytes (not including the type and length fields)

◆ getTotalLength()

uint16_t pcpp::SSLExtension::getTotalLength ( ) const
Returns
The total length of the extension, including type and length fields and the extension data field

◆ getType()

SSLExtensionType pcpp::SSLExtension::getType ( ) const
Returns
The type of the extension as enum

◆ getTypeAsInt()

uint16_t pcpp::SSLExtension::getTypeAsInt ( ) const
Returns
The type of the extension as a numeric value

◆ tryCreateExtension()

template<typename T , typename std::enable_if_t< std::is_base_of< SSLExtension, T >::value, bool > = true>
static std::unique_ptr<T> pcpp::SSLExtension::tryCreateExtension ( uint8_t *  data,
size_t  dataLen 
)
inlinestatic

A static method that tries to create an instance of a specific extension type.

The factory method handles potential buffer overflows by validating that the data length of the span is sufficient to contain the extension header (type and length fields) and the extension data as specified in the length field.

Template Parameters
TThe type of the extension to create. This type must be a class that inherits from SSLExtension.
Parameters
dataPointer to the raw data of the extension.
dataLenMax length of the span to be parsed.
Returns
The extension instance if the data buffer is valid, nullptr otherwise.