PcapPlusPlus  Next
Asn1Codec.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <memory>
5 #include <typeinfo>
6 #include <stdexcept>
7 #include <sstream>
8 #include <chrono>
9 #include <bitset>
10 #include "PointerVector.h"
11 
13 
16 namespace pcpp
17 {
19  enum class Asn1TagClass : uint8_t
20  {
22  Universal = 0,
24  Application = 1,
26  ContextSpecific = 2,
28  Private = 3,
29  };
30 
32  enum class Asn1UniversalTagType : uint8_t
33  {
35  EndOfContent = 0,
37  Boolean = 1,
39  Integer = 2,
41  BitString = 3,
43  OctetString = 4,
45  Null = 5,
47  ObjectIdentifier = 6,
49  ObjectDescriptor = 7,
51  External = 8,
53  Real = 9,
55  Enumerated = 10,
57  EmbeddedPDV = 11,
59  UTF8String = 12,
63  Time = 14,
65  Reserved = 15,
67  Sequence = 16,
69  Set = 17,
71  NumericString = 18,
73  PrintableString = 19,
75  T61String = 20,
77  VideotexString = 21,
79  IA5String = 22,
81  UTCTime = 23,
83  GeneralizedTime = 24,
85  GraphicString = 25,
87  VisibleString = 26,
89  GeneralString = 27,
91  UniversalString = 28,
93  CharacterString = 29,
95  BMPString = 30,
97  Date = 31,
99  TimeOfDay = 32,
101  DateTime = 33,
103  Duration = 34,
105  ObjectIdentifierIRI = 35,
109  NotApplicable = 255
110  };
111 
112  namespace internal
113  {
117  enum class Asn1LoadPolicy
118  {
120  Lazy,
122  Eager
123  };
124  } // namespace internal
125 
131  {
132  public:
140  static std::unique_ptr<Asn1Record> decode(const uint8_t* data, size_t dataLen, bool lazy = true);
141 
144  std::vector<uint8_t> encode() const;
145 
148  {
149  return m_TagClass;
150  }
151 
153  bool isConstructed() const
154  {
155  return m_IsConstructed;
156  }
157 
161 
163  uint8_t getTagType() const
164  {
165  return m_TagType;
166  }
167 
169  size_t getValueLength() const
170  {
171  return m_ValueLength;
172  }
173 
175  size_t getTotalLength() const
176  {
177  return m_TotalLength;
178  }
179 
181  std::string toString() const;
182 
187  template <class Asn1RecordType> Asn1RecordType* castAs()
188  {
189  auto result = dynamic_cast<Asn1RecordType*>(this);
190  if (result == nullptr)
191  {
192  throw std::bad_cast();
193  }
194  return result;
195  }
196 
197  virtual ~Asn1Record() = default;
198 
199  protected:
201  bool m_IsConstructed = false;
202  uint8_t m_TagType = 0;
203 
204  size_t m_ValueLength = 0;
205  size_t m_TotalLength = 0;
206 
207  Asn1Record() = default;
208 
211  virtual void decodeValue(uint8_t const* data) const = 0;
212 
215  virtual std::vector<uint8_t> encodeValue() const = 0;
216 
218  std::vector<uint8_t> encodeValueSafe() const
219  {
220  decodeValueIfNeeded();
221  return encodeValue();
222  }
223 
224  static std::unique_ptr<Asn1Record> decodeTagAndCreateRecord(const uint8_t* data, size_t dataLen,
225  uint8_t& tagLen);
226  uint8_t decodeLength(const uint8_t* data, size_t dataLen);
227  void decodeValueIfNeeded() const;
228 
229  uint8_t encodeTag() const;
230  std::vector<uint8_t> encodeLength() const;
231 
232  // note: Requires the value to be decoded first if lazy decoding is used
233  virtual std::vector<std::string> toStringList() const;
234 
235  friend class Asn1ConstructedRecord;
236 
237  private:
238  void setEncodedValue(uint8_t const* dataSource,
239  internal::Asn1LoadPolicy loadPolicy = internal::Asn1LoadPolicy::Lazy);
240 
241  mutable uint8_t const* m_EncodedValue = nullptr;
242  };
243 
248  {
249  friend class Asn1Record;
250 
251  public:
258  Asn1GenericRecord(Asn1TagClass tagClass, bool isConstructed, uint8_t tagType, const uint8_t* value,
259  size_t valueLen);
260 
266  Asn1GenericRecord(Asn1TagClass tagClass, bool isConstructed, uint8_t tagType, const std::string& value);
267 
268  ~Asn1GenericRecord() override = default;
269 
271  const uint8_t* getValue()
272  {
273  decodeValueIfNeeded();
274  return m_Value.get();
275  }
276 
277  protected:
278  Asn1GenericRecord() = default;
279 
280  void decodeValue(uint8_t const* data) const override;
281  std::vector<uint8_t> encodeValue() const override;
282 
283  private:
284  mutable std::unique_ptr<uint8_t[]> m_Value = nullptr;
285 
286  void init(Asn1TagClass tagClass, bool isConstructed, uint8_t tagType, const uint8_t* value, size_t valueLen);
287  };
288 
292  {
293  friend class Asn1Record;
294 
295  public:
300  explicit Asn1ConstructedRecord(Asn1TagClass tagClass, uint8_t tagType,
301  const std::vector<Asn1Record*>& subRecords);
302 
307  explicit Asn1ConstructedRecord(Asn1TagClass tagClass, uint8_t tagType,
308  const PointerVector<Asn1Record>& subRecords);
309 
313  {
314  decodeValueIfNeeded();
315  return m_SubRecords;
316  };
317 
318  protected:
319  Asn1ConstructedRecord() = default;
320 
321  void decodeValue(uint8_t const* data) const override;
322  std::vector<uint8_t> encodeValue() const override;
323 
324  std::vector<std::string> toStringList() const override;
325 
326  template <typename Iterator> void init(Asn1TagClass tagClass, uint8_t tagType, Iterator begin, Iterator end)
327  {
328  m_TagType = tagType;
329  m_TagClass = tagClass;
330  m_IsConstructed = true;
331 
332  size_t recordValueLength = 0;
333  for (Iterator recordIter = begin; recordIter != end; ++recordIter)
334  {
335  auto encodedRecord = (*recordIter)->encode();
336  auto copyRecord = Asn1Record::decode(encodedRecord.data(), encodedRecord.size(), LazySubRecordDecoding);
337  m_SubRecords.pushBack(std::move(copyRecord));
338  recordValueLength += encodedRecord.size();
339  }
340 
341  m_ValueLength = recordValueLength;
342  m_TotalLength = recordValueLength + 1 + (m_ValueLength < 128 ? 1 : 2);
343  }
344 
345  private:
346  // Set to false as there are issues with lazy decoding of sub-records in some cases.
347  static constexpr bool LazySubRecordDecoding = false;
348 
349  mutable PointerVector<Asn1Record> m_SubRecords;
350  };
351 
355  {
356  friend class Asn1Record;
357 
358  public:
361  explicit Asn1SequenceRecord(const std::vector<Asn1Record*>& subRecords);
362 
365  explicit Asn1SequenceRecord(const PointerVector<Asn1Record>& subRecords);
366 
367  private:
368  Asn1SequenceRecord() = default;
369  };
370 
374  {
375  friend class Asn1Record;
376 
377  public:
380  explicit Asn1SetRecord(const std::vector<Asn1Record*>& subRecords);
381 
384  explicit Asn1SetRecord(const PointerVector<Asn1Record>& subRecords);
385 
386  private:
387  Asn1SetRecord() = default;
388  };
389 
394  {
395  friend class Asn1Record;
396 
397  protected:
398  Asn1PrimitiveRecord() = default;
399  explicit Asn1PrimitiveRecord(Asn1UniversalTagType tagType);
400  };
401 
405  {
406  friend class Asn1Record;
407 
408  public:
409  template <typename T>
410  using EnableIfUnsignedIntegral =
411  std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value, int>;
412 
415  explicit Asn1IntegerRecord(uint64_t value);
416 
420  explicit Asn1IntegerRecord(const std::string& value);
421 
424  template <typename T, EnableIfUnsignedIntegral<T> = 0> T getIntValue() const
425  {
426  decodeValueIfNeeded();
427  return m_Value.getInt<T>();
428  }
429 
431  PCPP_DEPRECATED("Use getIntValue instead")
432  uint32_t getValue()
433  {
434  return getIntValue<uint32_t>();
435  }
436 
440  std::string getValueAsString(bool removeLeadingZeros = false) const
441  {
442  decodeValueIfNeeded();
443  return m_Value.toString(removeLeadingZeros);
444  }
445 
446  protected:
447  Asn1IntegerRecord() = default;
448 
449  void decodeValue(uint8_t const* data) const override;
450  std::vector<uint8_t> encodeValue() const override;
451 
452  std::vector<std::string> toStringList() const override;
453 
454  private:
455  class BigInt
456  {
457  public:
458  BigInt() = default;
459 
460  template <typename T, EnableIfUnsignedIntegral<T> = 0> explicit BigInt(T value)
461  {
462  m_Value = initFromInt(value);
463  }
464 
465  explicit BigInt(const std::string& value);
466  BigInt(const BigInt& other);
467 
468  template <typename T, EnableIfUnsignedIntegral<T> = 0> BigInt& operator=(T value)
469  {
470  m_Value = initFromInt(value);
471  return *this;
472  }
473  BigInt& operator=(const std::string& value);
474  size_t size() const;
475 
476  template <typename T, EnableIfUnsignedIntegral<T> = 0> T getInt() const
477  {
478  if (!canFit<T>())
479  {
480  throw std::overflow_error("Value cannot fit into requested int type");
481  }
482 
483  std::stringstream sstream;
484  sstream << std::hex << m_Value;
485 
486  uint64_t result;
487  sstream >> result;
488  return static_cast<T>(result);
489  }
490 
491  template <typename T, EnableIfUnsignedIntegral<T> = 0> bool canFit() const
492  {
493  return sizeof(T) >= (m_Value.size() + 1) / 2;
494  }
495 
496  std::string toString(bool removeLeadingZeros = false) const;
497  std::vector<uint8_t> toBytes() const;
498 
499  private:
500  std::string m_Value;
501 
502  static std::string initFromString(const std::string& value);
503 
504  template <typename T, EnableIfUnsignedIntegral<T> = 0> static std::string initFromInt(T value)
505  {
506  std::stringstream ss;
507  ss << std::hex << static_cast<uint64_t>(value);
508  return ss.str();
509  }
510  };
511 
512  mutable BigInt m_Value;
513  };
514 
518  {
519  friend class Asn1Record;
520 
521  public:
524  explicit Asn1EnumeratedRecord(uint32_t value);
525 
526  private:
527  Asn1EnumeratedRecord() = default;
528  };
529 
533  template <Asn1UniversalTagType TagType> class Asn1StringRecord : public Asn1PrimitiveRecord
534  {
535  public:
537  std::string getValue() const
538  {
539  decodeValueIfNeeded();
540  return m_Value;
541  };
542 
543  protected:
545  {}
546 
547  explicit Asn1StringRecord(const std::string& value) : Asn1PrimitiveRecord(TagType), m_Value(value)
548  {
549  m_ValueLength = value.size();
550  m_TotalLength = m_ValueLength + 2;
551  }
552 
553  void decodeValue(uint8_t const* data) const override
554  {
555  m_Value = std::string(reinterpret_cast<char const*>(data), m_ValueLength);
556  }
557  std::vector<uint8_t> encodeValue() const override
558  {
559  return { m_Value.begin(), m_Value.end() };
560  }
561 
562  std::vector<std::string> toStringList() const override
563  {
564  return { Asn1Record::toStringList().front() + ", Value: " + getValue() };
565  }
566 
567  mutable std::string m_Value;
568  };
569 
572  class Asn1OctetStringRecord : public Asn1StringRecord<Asn1UniversalTagType::OctetString>
573  {
574  friend class Asn1Record;
575 
576  public:
577  using Asn1StringRecord::Asn1StringRecord;
578 
582  explicit Asn1OctetStringRecord(const uint8_t* value, size_t valueLength);
583 
586  explicit Asn1OctetStringRecord(const std::string& value) : Asn1StringRecord(value)
587  {}
588 
589  protected:
590  void decodeValue(uint8_t const* data) const override;
591  std::vector<uint8_t> encodeValue() const override;
592 
593  private:
594  Asn1OctetStringRecord() = default;
595 
596  mutable bool m_IsPrintable = true;
597  };
598 
601  class Asn1UTF8StringRecord : public Asn1StringRecord<Asn1UniversalTagType::UTF8String>
602  {
603  friend class Asn1Record;
604 
605  public:
608  explicit Asn1UTF8StringRecord(const std::string& value) : Asn1StringRecord(value)
609  {}
610 
611  private:
612  Asn1UTF8StringRecord() = default;
613  };
614 
617  class Asn1PrintableStringRecord : public Asn1StringRecord<Asn1UniversalTagType::PrintableString>
618  {
619  friend class Asn1Record;
620 
621  public:
624  explicit Asn1PrintableStringRecord(const std::string& value) : Asn1StringRecord(value)
625  {}
626 
627  private:
628  Asn1PrintableStringRecord() = default;
629  };
630 
633  class Asn1IA5StringRecord : public Asn1StringRecord<Asn1UniversalTagType::IA5String>
634  {
635  friend class Asn1Record;
636 
637  public:
640  explicit Asn1IA5StringRecord(const std::string& value) : Asn1StringRecord(value)
641  {}
642 
643  private:
644  Asn1IA5StringRecord() = default;
645  };
646 
650  {
651  friend class Asn1Record;
652 
653  public:
656  explicit Asn1BooleanRecord(bool value);
657 
659  bool getValue() const
660  {
661  decodeValueIfNeeded();
662  return m_Value;
663  };
664 
665  protected:
666  void decodeValue(uint8_t const* data) const override;
667  std::vector<uint8_t> encodeValue() const override;
668 
669  std::vector<std::string> toStringList() const override;
670 
671  private:
672  Asn1BooleanRecord() = default;
673 
674  mutable bool m_Value = false;
675  };
676 
680  {
681  friend class Asn1Record;
682 
683  public:
686 
687  protected:
688  void decodeValue(uint8_t const* data) const override
689  {}
690  std::vector<uint8_t> encodeValue() const override
691  {
692  return {};
693  }
694  };
695 
699  {
700  friend class Asn1ObjectIdentifierRecord;
701 
702  public:
706  explicit Asn1ObjectIdentifier(const uint8_t* data, size_t dataLen);
707 
711  explicit Asn1ObjectIdentifier(const std::string& oidString);
712 
714  const std::vector<uint32_t>& getComponents() const
715  {
716  return m_Components;
717  }
718 
721  bool operator==(const Asn1ObjectIdentifier& other) const
722  {
723  return m_Components == other.m_Components;
724  }
725 
728  bool operator!=(const Asn1ObjectIdentifier& other) const
729  {
730  return m_Components != other.m_Components;
731  }
732 
735  std::string toString() const;
736 
739  std::vector<uint8_t> toBytes() const;
740 
741  friend std::ostream& operator<<(std::ostream& os, const Asn1ObjectIdentifier& oid)
742  {
743  return os << oid.toString();
744  }
745 
746  protected:
747  Asn1ObjectIdentifier() = default;
748 
749  private:
750  std::vector<uint32_t> m_Components;
751  };
752 
756  {
757  friend class Asn1Record;
758 
759  public:
763 
766  {
767  decodeValueIfNeeded();
768  return m_Value;
769  }
770 
771  protected:
772  void decodeValue(uint8_t const* data) const override;
773  std::vector<uint8_t> encodeValue() const override;
774 
775  std::vector<std::string> toStringList() const override;
776 
777  private:
778  mutable Asn1ObjectIdentifier m_Value;
779 
780  Asn1ObjectIdentifierRecord() = default;
781  };
782 
787  {
788  public:
793  std::chrono::system_clock::time_point getValue(const std::string& timezone = "Z") const
794  {
795  decodeValueIfNeeded();
796  return adjustTimezones(m_Value, "Z", timezone);
797  };
798 
805  std::string getValueAsString(const std::string& format = "%Y-%m-%d %H:%M:%S", const std::string& timezone = "Z",
806  bool includeMilliseconds = false) const;
807 
808  protected:
809  Asn1TimeRecord() = default;
810  explicit Asn1TimeRecord(Asn1UniversalTagType tagType, const std::chrono::system_clock::time_point& value,
811  const std::string& timezone);
812 
813  mutable std::chrono::system_clock::time_point m_Value;
814 
815  std::vector<std::string> toStringList() const override;
816 
817  static void validateTimezone(const std::string& timezone);
818  static std::chrono::system_clock::time_point adjustTimezones(const std::chrono::system_clock::time_point& value,
819  const std::string& fromTimezone,
820  const std::string& toTimezone);
821  };
822 
826  {
827  friend class Asn1Record;
828 
829  public:
833  explicit Asn1UtcTimeRecord(const std::chrono::system_clock::time_point& value, bool withSeconds = true);
834 
835  protected:
836  void decodeValue(uint8_t const* data) const override;
837  std::vector<uint8_t> encodeValue() const override;
838 
839  private:
840  Asn1UtcTimeRecord() = default;
841  mutable bool m_WithSeconds = true;
842  };
843 
847  {
848  friend class Asn1Record;
849 
850  public:
856  explicit Asn1GeneralizedTimeRecord(const std::chrono::system_clock::time_point& value,
857  const std::string& timezone = "Z");
858 
859  protected:
860  void decodeValue(uint8_t const* data) const override;
861  std::vector<uint8_t> encodeValue() const override;
862 
863  private:
864  Asn1GeneralizedTimeRecord() = default;
865  mutable std::string m_Timezone;
866  };
867 
871  {
872  friend class Asn1Record;
873 
874  public:
878  explicit Asn1BitStringRecord(const std::string& value);
879 
881  std::string getValue()
882  {
883  decodeValueIfNeeded();
884  return m_Value.toString();
885  };
886 
888  std::vector<uint8_t> getVecValue()
889  {
890  decodeValueIfNeeded();
891  return m_Value.toBytes();
892  }
893 
894  protected:
895  void decodeValue(uint8_t const* data) const override;
896  std::vector<uint8_t> encodeValue() const override;
897 
898  std::vector<std::string> toStringList() const override;
899 
900  private:
901  class BitSet
902  {
903  public:
904  BitSet() = default;
905  explicit BitSet(const std::string& value);
906  BitSet(const uint8_t* data, size_t numBits);
907 
908  BitSet& operator=(const std::string& value);
909 
910  size_t sizeInBytes() const;
911  std::string toString() const;
912  std::vector<uint8_t> toBytes() const;
913  size_t getNumBits() const
914  {
915  return m_NumBits;
916  }
917 
918  private:
919  void initFromString(const std::string& value);
920 
921  std::vector<std::bitset<8>> m_Data;
922  size_t m_NumBits = 0;
923  };
924 
925  Asn1BitStringRecord() = default;
926 
927  mutable BitSet m_Value;
928  };
929 } // namespace pcpp
Asn1LoadPolicy
Policy for when to evaluate (decode) ASN.1 record values. Determines whether the value is decoded imm...
Definition: Asn1Codec.h:118
@ Lazy
The value is evaluated on first access (lazy decoding).
@ Eager
The value is evaluated immediately on construction (eager decoding).
Definition: Asn1Codec.h:871
std::string getValue()
Definition: Asn1Codec.h:881
std::vector< uint8_t > getVecValue()
Definition: Asn1Codec.h:888
Asn1BitStringRecord(const std::string &value)
std::vector< uint8_t > encodeValue() const override
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
void decodeValue(uint8_t const *data) const override
Decodes the record value from a byte array into the mutable cache variables. This method is marked as...
Definition: Asn1Codec.h:650
void decodeValue(uint8_t const *data) const override
Decodes the record value from a byte array into the mutable cache variables. This method is marked as...
bool getValue() const
Definition: Asn1Codec.h:659
Asn1BooleanRecord(bool value)
std::vector< uint8_t > encodeValue() const override
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
Definition: Asn1Codec.h:292
std::vector< uint8_t > encodeValue() const override
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
PointerVector< Asn1Record > & getSubRecords()
Definition: Asn1Codec.h:312
void decodeValue(uint8_t const *data) const override
Decodes the record value from a byte array into the mutable cache variables. This method is marked as...
Asn1ConstructedRecord(Asn1TagClass tagClass, uint8_t tagType, const PointerVector< Asn1Record > &subRecords)
Asn1ConstructedRecord(Asn1TagClass tagClass, uint8_t tagType, const std::vector< Asn1Record * > &subRecords)
Definition: Asn1Codec.h:518
Asn1EnumeratedRecord(uint32_t value)
Definition: Asn1Codec.h:847
void decodeValue(uint8_t const *data) const override
Decodes the record value from a byte array into the mutable cache variables. This method is marked as...
std::vector< uint8_t > encodeValue() const override
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
Asn1GeneralizedTimeRecord(const std::chrono::system_clock::time_point &value, const std::string &timezone="Z")
Definition: Asn1Codec.h:248
std::vector< uint8_t > encodeValue() const override
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
const uint8_t * getValue()
Definition: Asn1Codec.h:271
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)
void decodeValue(uint8_t const *data) const override
Decodes the record value from a byte array into the mutable cache variables. This method is marked as...
Definition: Asn1Codec.h:634
Asn1IA5StringRecord(const std::string &value)
Definition: Asn1Codec.h:640
Definition: Asn1Codec.h:405
T getIntValue() const
Definition: Asn1Codec.h:424
std::vector< uint8_t > encodeValue() const override
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
Asn1IntegerRecord(uint64_t value)
void decodeValue(uint8_t const *data) const override
Decodes the record value from a byte array into the mutable cache variables. This method is marked as...
uint32_t getValue()
Definition: Asn1Codec.h:432
std::string getValueAsString(bool removeLeadingZeros=false) const
Definition: Asn1Codec.h:440
Asn1IntegerRecord(const std::string &value)
Definition: Asn1Codec.h:680
void decodeValue(uint8_t const *data) const override
Decodes the record value from a byte array into the mutable cache variables. This method is marked as...
Definition: Asn1Codec.h:688
std::vector< uint8_t > encodeValue() const override
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
Definition: Asn1Codec.h:690
Asn1NullRecord()
A constructor to create a record of type Null.
Definition: Asn1Codec.h:699
std::vector< uint8_t > toBytes() const
bool operator==(const Asn1ObjectIdentifier &other) const
Definition: Asn1Codec.h:721
std::string toString() const
Asn1ObjectIdentifier(const uint8_t *data, size_t dataLen)
bool operator!=(const Asn1ObjectIdentifier &other) const
Definition: Asn1Codec.h:728
Asn1ObjectIdentifier(const std::string &oidString)
const std::vector< uint32_t > & getComponents() const
Definition: Asn1Codec.h:714
Definition: Asn1Codec.h:756
void decodeValue(uint8_t const *data) const override
Decodes the record value from a byte array into the mutable cache variables. This method is marked as...
const Asn1ObjectIdentifier & getValue() const
Definition: Asn1Codec.h:765
Asn1ObjectIdentifierRecord(const Asn1ObjectIdentifier &value)
std::vector< uint8_t > encodeValue() const override
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
Definition: Asn1Codec.h:573
Asn1OctetStringRecord(const std::string &value)
Definition: Asn1Codec.h:586
void decodeValue(uint8_t const *data) const override
Decodes the record value from a byte array into the mutable cache variables. This method is marked as...
std::vector< uint8_t > encodeValue() const override
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
Asn1OctetStringRecord(const uint8_t *value, size_t valueLength)
Definition: Asn1Codec.h:394
Definition: Asn1Codec.h:618
Asn1PrintableStringRecord(const std::string &value)
Definition: Asn1Codec.h:624
Definition: Asn1Codec.h:131
std::string toString() const
uint8_t getTagType() const
Definition: Asn1Codec.h:163
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...
bool isConstructed() const
Definition: Asn1Codec.h:153
Asn1UniversalTagType getUniversalTagType() const
Asn1TagClass getTagClass() const
Definition: Asn1Codec.h:147
size_t getTotalLength() const
Definition: Asn1Codec.h:175
Asn1RecordType * castAs()
Definition: Asn1Codec.h:187
std::vector< uint8_t > encode() const
size_t getValueLength() const
Definition: Asn1Codec.h:169
std::vector< uint8_t > encodeValueSafe() const
Encodes the record value into a byte array, ensuring that the value is decoded first if needed.
Definition: Asn1Codec.h:218
static std::unique_ptr< Asn1Record > decode(const uint8_t *data, size_t dataLen, bool lazy=true)
virtual std::vector< uint8_t > encodeValue() const =0
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
Definition: Asn1Codec.h:355
Asn1SequenceRecord(const PointerVector< Asn1Record > &subRecords)
Asn1SequenceRecord(const std::vector< Asn1Record * > &subRecords)
Definition: Asn1Codec.h:374
Asn1SetRecord(const PointerVector< Asn1Record > &subRecords)
Asn1SetRecord(const std::vector< Asn1Record * > &subRecords)
Definition: Asn1Codec.h:534
std::string getValue() const
Definition: Asn1Codec.h:537
void decodeValue(uint8_t const *data) const override
Decodes the record value from a byte array into the mutable cache variables. This method is marked as...
Definition: Asn1Codec.h:553
std::vector< uint8_t > encodeValue() const override
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
Definition: Asn1Codec.h:557
Definition: Asn1Codec.h:787
std::chrono::system_clock::time_point getValue(const std::string &timezone="Z") const
Definition: Asn1Codec.h:793
std::string getValueAsString(const std::string &format="%Y-%m-%d %H:%M:%S", const std::string &timezone="Z", bool includeMilliseconds=false) const
Definition: Asn1Codec.h:602
Asn1UTF8StringRecord(const std::string &value)
Definition: Asn1Codec.h:608
Definition: Asn1Codec.h:826
std::vector< uint8_t > encodeValue() const override
Encodes the record value into a byte array Prefer using encodeValueSafe() to ensure the value is deco...
void decodeValue(uint8_t const *data) const override
Decodes the record value from a byte array into the mutable cache variables. This method is marked as...
Asn1UtcTimeRecord(const std::chrono::system_clock::time_point &value, bool withSeconds=true)
Definition: PointerVector.h:50
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19
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.