126 static std::unique_ptr<Asn1Record>
decode(
const uint8_t* data,
size_t dataLen,
bool lazy =
true);
141 return m_IsConstructed;
157 return m_ValueLength;
163 return m_TotalLength;
173 template <
class Asn1RecordType> Asn1RecordType*
castAs()
175 auto result =
dynamic_cast<Asn1RecordType*
>(
this);
176 if (result ==
nullptr)
178 throw std::bad_cast();
187 bool m_IsConstructed =
false;
188 uint8_t m_TagType = 0;
190 size_t m_ValueLength = 0;
191 size_t m_TotalLength = 0;
193 uint8_t* m_EncodedValue =
nullptr;
197 static Asn1Record* decodeInternal(
const uint8_t* data,
size_t dataLen,
bool lazy);
199 virtual void decodeValue(uint8_t* data,
bool lazy) = 0;
200 virtual std::vector<uint8_t> encodeValue()
const = 0;
202 static Asn1Record* decodeTagAndCreateRecord(
const uint8_t* data,
size_t dataLen, uint8_t& tagLen);
203 uint8_t decodeLength(
const uint8_t* data,
size_t dataLen);
204 void decodeValueIfNeeded();
207 std::vector<uint8_t> encodeLength()
const;
209 virtual std::vector<std::string> toStringList();
243 decodeValueIfNeeded();
250 void decodeValue(uint8_t* data,
bool lazy)
override;
251 std::vector<uint8_t> encodeValue()
const override;
254 uint8_t* m_Value =
nullptr;
271 const std::vector<Asn1Record*>& subRecords);
284 decodeValueIfNeeded();
291 void decodeValue(uint8_t* data,
bool lazy)
override;
292 std::vector<uint8_t> encodeValue()
const override;
294 std::vector<std::string> toStringList()
override;
296 template <
typename Iterator>
void init(
Asn1TagClass tagClass, uint8_t tagType, Iterator begin, Iterator end)
299 m_TagClass = tagClass;
300 m_IsConstructed =
true;
302 size_t recordValueLength = 0;
303 for (Iterator recordIter = begin; recordIter != end; ++recordIter)
305 auto encodedRecord = (*recordIter)->encode();
306 auto copyRecord =
Asn1Record::decode(encodedRecord.data(), encodedRecord.size(),
false);
307 m_SubRecords.pushBack(std::move(copyRecord));
308 recordValueLength += encodedRecord.size();
311 m_ValueLength = recordValueLength;
312 m_TotalLength = recordValueLength + 1 + (m_ValueLength < 128 ? 1 : 2);
316 PointerVector<Asn1Record> m_SubRecords;
376 template <
typename T>
377 using EnableIfUnsignedIntegral =
378 std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value,
int>;
391 template <
typename T, EnableIfUn
signedIntegral<T> = 0> T
getIntValue()
393 decodeValueIfNeeded();
394 return m_Value.getInt<T>();
398 PCPP_DEPRECATED(
"Use getIntValue instead")
401 return getIntValue<uint32_t>();
407 decodeValueIfNeeded();
408 return m_Value.toString();
414 void decodeValue(uint8_t* data,
bool lazy)
override;
415 std::vector<uint8_t> encodeValue()
const override;
417 std::vector<std::string> toStringList()
override;
425 template <
typename T, EnableIfUn
signedIntegral<T> = 0>
explicit BigInt(T value)
427 m_Value = initFromInt(value);
430 explicit BigInt(
const std::string& value);
431 BigInt(
const BigInt& other);
433 template <
typename T, EnableIfUn
signedIntegral<T> = 0> BigInt& operator=(T value)
435 m_Value = initFromInt(value);
438 BigInt& operator=(
const std::string& value);
441 template <
typename T, EnableIfUn
signedIntegral<T> = 0> T getInt()
const
445 throw std::overflow_error(
"Value cannot fit into requested int type");
448 std::stringstream sstream;
449 sstream << std::hex << m_Value;
453 return static_cast<T
>(result);
456 template <
typename T, EnableIfUn
signedIntegral<T> = 0>
bool canFit()
const
458 return sizeof(T) >= (m_Value.size() + 1) / 2;
462 std::vector<uint8_t> toBytes()
const;
467 static std::string initFromString(
const std::string& value);
469 template <
typename T, EnableIfUn
signedIntegral<T> = 0>
static std::string initFromInt(T value)
471 std::stringstream ss;
472 ss << std::hex << static_cast<uint64_t>(value);
514 decodeValueIfNeeded();
519 void decodeValue(uint8_t* data,
bool lazy)
override;
520 std::vector<uint8_t> encodeValue()
const override;
522 std::vector<std::string> toStringList()
override;
526 bool m_IsPrintable =
true;
545 decodeValueIfNeeded();
550 void decodeValue(uint8_t* data,
bool lazy)
override;
551 std::vector<uint8_t> encodeValue()
const override;
553 std::vector<std::string> toStringList()
override;
558 bool m_Value =
false;
572 void decodeValue(uint8_t* data,
bool lazy)
override
574 std::vector<uint8_t> encodeValue()
const override
607 return m_Components == other.m_Components;
614 return m_Components != other.m_Components;
634 std::vector<uint32_t> m_Components;
651 decodeValueIfNeeded();
656 void decodeValue(uint8_t* data,
bool lazy)
override;
657 std::vector<uint8_t> encodeValue()
const override;
659 std::vector<std::string> toStringList()
override;
677 std::chrono::system_clock::time_point
getValue(
const std::string& timezone =
"Z")
679 decodeValueIfNeeded();
680 return adjustTimezones(m_Value,
"Z", timezone);
689 std::string
getValueAsString(
const std::string& format =
"%Y-%m-%d %H:%M:%S",
const std::string& timezone =
"Z",
690 bool includeMilliseconds =
false);
695 const std::string& timezone);
697 std::chrono::system_clock::time_point m_Value;
699 std::vector<std::string> toStringList()
override;
701 static void validateTimezone(
const std::string& timezone);
702 static std::chrono::system_clock::time_point adjustTimezones(
const std::chrono::system_clock::time_point& value,
703 const std::string& fromTimezone,
704 const std::string& toTimezone);
717 explicit Asn1UtcTimeRecord(
const std::chrono::system_clock::time_point& value,
bool withSeconds =
true);
720 void decodeValue(uint8_t* data,
bool lazy)
override;
721 std::vector<uint8_t> encodeValue()
const override;
725 bool m_WithSeconds =
true;
741 const std::string& timezone =
"Z");
744 void decodeValue(uint8_t* data,
bool lazy)
override;
745 std::vector<uint8_t> encodeValue()
const override;
749 std::string m_Timezone;
767 decodeValueIfNeeded();
768 return m_Value.toString();
772 void decodeValue(uint8_t* data,
bool lazy)
override;
773 std::vector<uint8_t> encodeValue()
const override;
775 std::vector<std::string> toStringList()
override;
782 explicit BitSet(
const std::string& value);
783 BitSet(
const uint8_t* data,
size_t numBits);
785 BitSet& operator=(
const std::string& value);
787 size_t sizeInBytes()
const;
789 std::vector<uint8_t> toBytes()
const;
790 size_t getNumBits()
const
796 void initFromString(
const std::string& value);
798 std::vector<std::bitset<8>> m_Data;
799 size_t m_NumBits = 0;
Definition: Asn1Codec.h:755
std::string getValue()
Definition: Asn1Codec.h:765
Asn1BitStringRecord(const std::string &value)
Definition: Asn1Codec.h:534
Asn1BooleanRecord(bool value)
bool getValue()
Definition: Asn1Codec.h:543
Definition: Asn1Codec.h:262
PointerVector< Asn1Record > & getSubRecords()
Definition: Asn1Codec.h:282
Asn1ConstructedRecord(Asn1TagClass tagClass, uint8_t tagType, const PointerVector< Asn1Record > &subRecords)
Asn1ConstructedRecord(Asn1TagClass tagClass, uint8_t tagType, const std::vector< Asn1Record * > &subRecords)
Definition: Asn1Codec.h:483
Asn1EnumeratedRecord(uint32_t value)
Definition: Asn1Codec.h:731
Asn1GeneralizedTimeRecord(const std::chrono::system_clock::time_point &value, const std::string &timezone="Z")
Definition: Asn1Codec.h:218
const uint8_t * getValue()
Definition: Asn1Codec.h:241
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:372
Asn1IntegerRecord(uint64_t value)
T getIntValue()
Definition: Asn1Codec.h:391
uint32_t getValue()
Definition: Asn1Codec.h:399
std::string getValueAsString()
Definition: Asn1Codec.h:405
Asn1IntegerRecord(const std::string &value)
Definition: Asn1Codec.h:564
Asn1NullRecord()
A constructor to create a record of type Null.
Definition: Asn1Codec.h:583
std::vector< uint8_t > toBytes() const
bool operator==(const Asn1ObjectIdentifier &other) const
Definition: Asn1Codec.h:605
std::string toString() const
Asn1ObjectIdentifier(const uint8_t *data, size_t dataLen)
bool operator!=(const Asn1ObjectIdentifier &other) const
Definition: Asn1Codec.h:612
Asn1ObjectIdentifier(const std::string &oidString)
const std::vector< uint32_t > & getComponents() const
Definition: Asn1Codec.h:598
Definition: Asn1Codec.h:640
const Asn1ObjectIdentifier & getValue()
Definition: Asn1Codec.h:649
Asn1ObjectIdentifierRecord(const Asn1ObjectIdentifier &value)
Definition: Asn1Codec.h:498
Asn1OctetStringRecord(const std::string &value)
std::string getValue()
Definition: Asn1Codec.h:512
Asn1OctetStringRecord(const uint8_t *value, size_t valueLength)
Definition: Asn1Codec.h:361
Definition: Asn1Codec.h:117
uint8_t getTagType() const
Definition: Asn1Codec.h:149
std::vector< uint8_t > encode()
bool isConstructed() const
Definition: Asn1Codec.h:139
Asn1UniversalTagType getUniversalTagType() const
Asn1TagClass getTagClass() const
Definition: Asn1Codec.h:133
size_t getTotalLength() const
Definition: Asn1Codec.h:161
Asn1RecordType * castAs()
Definition: Asn1Codec.h:173
size_t getValueLength() const
Definition: Asn1Codec.h:155
static std::unique_ptr< Asn1Record > decode(const uint8_t *data, size_t dataLen, bool lazy=true)
Definition: Asn1Codec.h:322
Asn1SequenceRecord(const PointerVector< Asn1Record > &subRecords)
Asn1SequenceRecord(const std::vector< Asn1Record * > &subRecords)
Definition: Asn1Codec.h:341
Asn1SetRecord(const PointerVector< Asn1Record > &subRecords)
Asn1SetRecord(const std::vector< Asn1Record * > &subRecords)
Definition: Asn1Codec.h:671
std::string getValueAsString(const std::string &format="%Y-%m-%d %H:%M:%S", const std::string &timezone="Z", bool includeMilliseconds=false)
std::chrono::system_clock::time_point getValue(const std::string &timezone="Z")
Definition: Asn1Codec.h:677
Definition: Asn1Codec.h:710
Asn1UtcTimeRecord(const std::chrono::system_clock::time_point &value, bool withSeconds=true)
Definition: PointerVector.h:50
The main namespace for the PcapPlusPlus lib.
Asn1TagClass
An enum for representing ASN.1 tag class.
Definition: Asn1Codec.h:20
@ ContextSpecific
The Context-Specific tag class.
@ Private
The Private tag class.
@ Universal
The Universal tag class.
@ Application
The Application tag class.
Asn1UniversalTagType
An enum for representing ASN.1 Universal tag types.
Definition: Asn1Codec.h:33
@ BitString
The universal tag type for Bit String.
@ Enumerated
The universal tag type for Enumerated.
@ ObjectIdentifierIRI
The universal tag type for Object Identifier Internationalized Resource Identifier (IRI)
@ ObjectDescriptor
The universal tag type for Object Descriptor.
@ TimeOfDay
The universal tag type for Time of Day.
@ GraphicString
The universal tag type for GraphicString.
@ UTCTime
The universal tag type for UTC time.
@ Boolean
The universal tag type for Boolean.
@ EmbeddedPDV
The universal tag type for Embedded-PDV.
@ OctetString
The universal tag type for Octet String.
@ UniversalString
The universal tag type for UniversalString.
@ Sequence
The universal tag type Sequence.
@ Date
The universal tag type for Date.
@ RelativeObjectIdentifierIRI
The universal tag type for Relative Object Identifier Internationalized Resource Identifier (IRI)
@ PrintableString
The universal tag type for Printable String.
@ CharacterString
The universal tag type for CharacterString.
@ RelativeObjectIdentifier
The universal tag type for Relative Object Identifier.
@ Set
The universal tag type for Set.
@ ObjectIdentifier
The universal tag type for Object Identifier.
@ IA5String
The universal tag type for IA5String.
@ VideotexString
The universal tag type for Videotex String.
@ NotApplicable
A non-applicable value.
@ Real
The universal tag type for Real.
@ DateTime
The universal tag type for Date-Time.
@ EndOfContent
The reserved identifier for the End-of-Contents marker in an indefinite length encoding.
@ Reserved
A reserved value.
@ Integer
The universal tag type for Integer.
@ Time
The universal tag type for Time.
@ External
The universal tag type for External.
@ BMPString
The universal tag type for BMPString.
@ UTF8String
The universal tag type for UTF8 String.
@ Null
The universal tag type for Null.
@ GeneralizedTime
The universal tag type for Generalized time.
@ T61String
The universal tag type for T61String.
@ Duration
The universal tag type for Duration.
@ VisibleString
The universal tag type for VisibleString.
@ GeneralString
The universal tag type for GeneralString.
@ NumericString
The universal tag type for Numeric String.