134 static std::unique_ptr<Asn1Record>
decode(
const uint8_t* data,
size_t dataLen,
bool lazy =
true);
155 return m_IsConstructed;
177 return m_ValueLength;
185 return m_TotalLength;
199 template <
class Asn1RecordType> Asn1RecordType*
castAs()
201 auto result =
dynamic_cast<Asn1RecordType*
>(
this);
202 if (result ==
nullptr)
204 throw std::bad_cast();
213 bool m_IsConstructed =
false;
214 uint8_t m_TagType = 0;
216 size_t m_ValueLength = 0;
217 size_t m_TotalLength = 0;
219 uint8_t* m_EncodedValue =
nullptr;
223 static Asn1Record* decodeInternal(
const uint8_t* data,
size_t dataLen,
bool lazy);
225 virtual void decodeValue(uint8_t* data,
bool lazy) = 0;
226 virtual std::vector<uint8_t> encodeValue()
const = 0;
228 static Asn1Record* decodeTagAndCreateRecord(
const uint8_t* data,
size_t dataLen, uint8_t& tagLen);
229 uint8_t decodeLength(
const uint8_t* data,
size_t dataLen);
230 void decodeValueIfNeeded();
233 std::vector<uint8_t> encodeLength()
const;
235 virtual std::vector<std::string> toStringList();
277 decodeValueIfNeeded();
284 void decodeValue(uint8_t* data,
bool lazy)
override;
285 std::vector<uint8_t> encodeValue()
const override;
288 uint8_t* m_Value =
nullptr;
309 const std::vector<Asn1Record*>& subRecords);
326 decodeValueIfNeeded();
333 void decodeValue(uint8_t* data,
bool lazy)
override;
334 std::vector<uint8_t> encodeValue()
const override;
336 std::vector<std::string> toStringList()
override;
338 template <
typename Iterator>
void init(
Asn1TagClass tagClass, uint8_t tagType, Iterator begin, Iterator end)
341 m_TagClass = tagClass;
342 m_IsConstructed =
true;
344 size_t recordValueLength = 0;
345 for (Iterator recordIter = begin; recordIter != end; ++recordIter)
347 auto encodedRecord = (*recordIter)->encode();
348 auto copyRecord =
Asn1Record::decode(encodedRecord.data(), encodedRecord.size(),
false);
349 m_SubRecords.pushBack(std::move(copyRecord));
350 recordValueLength += encodedRecord.size();
353 m_ValueLength = recordValueLength;
354 m_TotalLength = recordValueLength + 1 + (m_ValueLength < 128 ? 1 : 2);
358 PointerVector<Asn1Record> m_SubRecords;
445 decodeValueIfNeeded();
452 void decodeValue(uint8_t* data,
bool lazy)
override;
453 std::vector<uint8_t> encodeValue()
const override;
455 std::vector<std::string> toStringList()
override;
458 uint32_t m_Value = 0;
507 decodeValueIfNeeded();
512 void decodeValue(uint8_t* data,
bool lazy)
override;
513 std::vector<uint8_t> encodeValue()
const override;
515 std::vector<std::string> toStringList()
override;
519 bool m_IsPrintable =
true;
544 decodeValueIfNeeded();
549 void decodeValue(uint8_t* data,
bool lazy)
override;
550 std::vector<uint8_t> encodeValue()
const override;
552 std::vector<std::string> toStringList()
override;
557 bool m_Value =
false;
575 void decodeValue(uint8_t* data,
bool lazy)
override
577 std::vector<uint8_t> encodeValue()
const override
Definition: Asn1Codec.h:529
Asn1BooleanRecord(bool value)
bool getValue()
Definition: Asn1Codec.h:542
Definition: Asn1Codec.h:298
PointerVector< Asn1Record > & getSubRecords()
Definition: Asn1Codec.h:324
Asn1ConstructedRecord(Asn1TagClass tagClass, uint8_t tagType, const PointerVector< Asn1Record > &subRecords)
Asn1ConstructedRecord(Asn1TagClass tagClass, uint8_t tagType, const std::vector< Asn1Record * > &subRecords)
Definition: Asn1Codec.h:466
Asn1EnumeratedRecord(uint32_t value)
Definition: Asn1Codec.h:246
const uint8_t * getValue()
Definition: Asn1Codec.h:275
Asn1GenericRecord(Asn1TagClass tagClass, bool isConstructed, uint8_t tagType, const uint8_t *value, size_t valueLen)
Asn1GenericRecord(Asn1TagClass tagClass, bool isConstructed, uint8_t tagType, const std::string &value)
Definition: Asn1Codec.h:430
Asn1IntegerRecord(uint32_t value)
uint32_t getValue()
Definition: Asn1Codec.h:443
Definition: Asn1Codec.h:565
Definition: Asn1Codec.h:485
Asn1OctetStringRecord(const std::string &value)
std::string getValue()
Definition: Asn1Codec.h:505
Asn1OctetStringRecord(const uint8_t *value, size_t valueLength)
Definition: Asn1Codec.h:417
Definition: Asn1Codec.h:123
uint8_t getTagType() const
Definition: Asn1Codec.h:167
std::vector< uint8_t > encode()
bool isConstructed() const
Definition: Asn1Codec.h:153
Asn1UniversalTagType getUniversalTagType() const
Asn1TagClass getTagClass() const
Definition: Asn1Codec.h:145
size_t getTotalLength() const
Definition: Asn1Codec.h:183
Asn1RecordType * castAs()
Definition: Asn1Codec.h:199
size_t getValueLength() const
Definition: Asn1Codec.h:175
static std::unique_ptr< Asn1Record > decode(const uint8_t *data, size_t dataLen, bool lazy=true)
Definition: Asn1Codec.h:366
Asn1SequenceRecord(const PointerVector< Asn1Record > &subRecords)
Asn1SequenceRecord(const std::vector< Asn1Record * > &subRecords)
Definition: Asn1Codec.h:391
Asn1SetRecord(const PointerVector< Asn1Record > &subRecords)
Asn1SetRecord(const std::vector< Asn1Record * > &subRecords)
Definition: PointerVector.h:58
The main namespace for the PcapPlusPlus lib.
Asn1TagClass
Definition: Asn1Codec.h:21
Asn1UniversalTagType
Definition: Asn1Codec.h:36
@ RelativeObjectIdentifierIRI
@ RelativeObjectIdentifier