PcapPlusPlus  Next
pcpp::Asn1Record Class Referenceabstract

#include <Asn1Codec.h>

Inheritance diagram for pcpp::Asn1Record:
pcpp::Asn1ConstructedRecord pcpp::Asn1GenericRecord pcpp::Asn1PrimitiveRecord pcpp::Asn1SequenceRecord pcpp::Asn1SetRecord pcpp::Asn1StringRecord< Asn1UniversalTagType::OctetString > pcpp::Asn1StringRecord< Asn1UniversalTagType::IA5String > pcpp::Asn1StringRecord< Asn1UniversalTagType::PrintableString > pcpp::Asn1StringRecord< Asn1UniversalTagType::UTF8String > pcpp::Asn1BitStringRecord pcpp::Asn1BooleanRecord pcpp::Asn1IntegerRecord pcpp::Asn1NullRecord pcpp::Asn1ObjectIdentifierRecord pcpp::Asn1StringRecord< TagType > pcpp::Asn1TimeRecord

Public Member Functions

std::vector< uint8_t > encode () const
 
Asn1TagClass getTagClass () const
 
bool isConstructed () const
 
Asn1UniversalTagType getUniversalTagType () const
 
uint8_t getTagType () const
 
size_t getValueLength () const
 
size_t getTotalLength () const
 
std::string toString () const
 
template<class Asn1RecordType >
Asn1RecordType * castAs ()
 

Static Public Member Functions

static std::unique_ptr< Asn1Recorddecode (const uint8_t *data, size_t dataLen, bool lazy=true)
 

Protected Member Functions

virtual void decodeValue (uint8_t const *data) const =0
 Decodes the record value from a byte array into the mutable cache variables. This method is marked as const as it can be called on a const instance of the record for lazy decoding.
 
virtual std::vector< uint8_t > encodeValue () const =0
 Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is decoded first if needed.
 
std::vector< uint8_t > encodeValueSafe () const
 Encodes the record value into a byte array, ensuring that the value is decoded first if needed.
 

Detailed Description

Represents an ASN.1 record, as described in ITU-T Recommendation X.680: https://www.itu.int/rec/T-REC-X.680/en https://en.wikipedia.org/wiki/ASN.1

Member Function Documentation

◆ castAs()

template<class Asn1RecordType >
Asn1RecordType* pcpp::Asn1Record::castAs ( )
inline

A templated method that accepts a class derived from Asn1Record as its template argument and attempts to cast the current instance to that type

Template Parameters
Asn1RecordTypeThe type to cast to
Returns
A pointer to the type after casting

◆ decode()

static std::unique_ptr<Asn1Record> pcpp::Asn1Record::decode ( const uint8_t *  data,
size_t  dataLen,
bool  lazy = true 
)
static

A static method to decode a byte array into an Asn1Record

Parameters
dataA byte array to decode
dataLenThe byte array length
lazyUse lazy decoding, set to true by default. Lazy decoding entails delaying the decoding of the record value until it is accessed
Returns
A smart pointer to the decoded ASN.1 record. If the byte stream is not a valid ASN.1 record an exception is thrown

◆ encode()

std::vector<uint8_t> pcpp::Asn1Record::encode ( ) const

Encode this record and convert it to a byte stream

Returns
A vector of bytes representing the record

◆ getTagClass()

Asn1TagClass pcpp::Asn1Record::getTagClass ( ) const
inline
Returns
The ASN.1 tag class

◆ getTagType()

uint8_t pcpp::Asn1Record::getTagType ( ) const
inline
Returns
The ASN.1 tag type value

◆ getTotalLength()

size_t pcpp::Asn1Record::getTotalLength ( ) const
inline
Returns
The total length of the record

◆ getUniversalTagType()

Asn1UniversalTagType pcpp::Asn1Record::getUniversalTagType ( ) const
Returns
The ASN.1 Universal tag type if the record is of class Universal, otherwise Asn1UniversalTagType::NotApplicable

◆ getValueLength()

size_t pcpp::Asn1Record::getValueLength ( ) const
inline
Returns
The length of the record value

◆ isConstructed()

bool pcpp::Asn1Record::isConstructed ( ) const
inline
Returns
True if it's a constructed record, or false if it's a primitive record

◆ toString()

std::string pcpp::Asn1Record::toString ( ) const
Returns
A string representation of the record