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>
461  explicit BigInt(T value) : m_Value(initFromInt(value))
462  {}
463 
464  explicit BigInt(const std::string& value);
465  BigInt(const BigInt& other);
466 
467  template <typename T, EnableIfUnsignedIntegral<T> = 0> BigInt& operator=(T value)
468  {
469  m_Value = initFromInt(value);
470  return *this;
471  }
472  BigInt& operator=(const std::string& value);
473  size_t size() const;
474 
475  template <typename T, EnableIfUnsignedIntegral<T> = 0> T getInt() const
476  {
477  if (!canFit<T>())
478  {
479  throw std::overflow_error("Value cannot fit into requested int type");
480  }
481 
482  std::stringstream sstream;
483  sstream << std::hex << m_Value;
484 
485  uint64_t result;
486  sstream >> result;
487  return static_cast<T>(result);
488  }
489 
490  template <typename T, EnableIfUnsignedIntegral<T> = 0> bool canFit() const
491  {
492  return sizeof(T) >= (m_Value.size() + 1) / 2;
493  }
494 
495  std::string toString(bool removeLeadingZeros = false) const;
496  std::vector<uint8_t> toBytes() const;
497 
498  private:
499  std::string m_Value;
500 
501  static std::string initFromString(const std::string& value);
502 
503  template <typename T, EnableIfUnsignedIntegral<T> = 0> static std::string initFromInt(T value)
504  {
505  std::stringstream ss;
506  ss << std::hex << static_cast<uint64_t>(value);
507  return ss.str();
508  }
509  };
510 
511  mutable BigInt m_Value;
512  };
513 
517  {
518  friend class Asn1Record;
519 
520  public:
523  explicit Asn1EnumeratedRecord(uint32_t value);
524 
525  private:
526  Asn1EnumeratedRecord() = default;
527  };
528 
532  template <Asn1UniversalTagType TagType> class Asn1StringRecord : public Asn1PrimitiveRecord
533  {
534  public:
536  std::string getValue() const
537  {
538  decodeValueIfNeeded();
539  return m_Value;
540  };
541 
542  protected:
544  {}
545 
546  explicit Asn1StringRecord(const std::string& value) : Asn1PrimitiveRecord(TagType), m_Value(value)
547  {
548  m_ValueLength = value.size();
549  m_TotalLength = m_ValueLength + 2;
550  }
551 
552  void decodeValue(uint8_t const* data) const override
553  {
554  m_Value = std::string(reinterpret_cast<char const*>(data), m_ValueLength);
555  }
556  std::vector<uint8_t> encodeValue() const override
557  {
558  return { m_Value.begin(), m_Value.end() };
559  }
560 
561  std::vector<std::string> toStringList() const override
562  {
563  return { Asn1Record::toStringList().front() + ", Value: " + getValue() };
564  }
565 
566  mutable std::string m_Value;
567  };
568 
571  class Asn1OctetStringRecord : public Asn1StringRecord<Asn1UniversalTagType::OctetString>
572  {
573  friend class Asn1Record;
574 
575  public:
576  using Asn1StringRecord::Asn1StringRecord;
577 
581  explicit Asn1OctetStringRecord(const uint8_t* value, size_t valueLength);
582 
585  explicit Asn1OctetStringRecord(const std::string& value) : Asn1StringRecord(value)
586  {}
587 
588  protected:
589  void decodeValue(uint8_t const* data) const override;
590  std::vector<uint8_t> encodeValue() const override;
591 
592  private:
593  Asn1OctetStringRecord() = default;
594 
595  mutable bool m_IsPrintable = true;
596  };
597 
600  class Asn1UTF8StringRecord : public Asn1StringRecord<Asn1UniversalTagType::UTF8String>
601  {
602  friend class Asn1Record;
603 
604  public:
607  explicit Asn1UTF8StringRecord(const std::string& value) : Asn1StringRecord(value)
608  {}
609 
610  private:
611  Asn1UTF8StringRecord() = default;
612  };
613 
616  class Asn1PrintableStringRecord : public Asn1StringRecord<Asn1UniversalTagType::PrintableString>
617  {
618  friend class Asn1Record;
619 
620  public:
623  explicit Asn1PrintableStringRecord(const std::string& value) : Asn1StringRecord(value)
624  {}
625 
626  private:
627  Asn1PrintableStringRecord() = default;
628  };
629 
632  class Asn1IA5StringRecord : public Asn1StringRecord<Asn1UniversalTagType::IA5String>
633  {
634  friend class Asn1Record;
635 
636  public:
639  explicit Asn1IA5StringRecord(const std::string& value) : Asn1StringRecord(value)
640  {}
641 
642  private:
643  Asn1IA5StringRecord() = default;
644  };
645 
649  {
650  friend class Asn1Record;
651 
652  public:
655  explicit Asn1BooleanRecord(bool value);
656 
658  bool getValue() const
659  {
660  decodeValueIfNeeded();
661  return m_Value;
662  };
663 
664  protected:
665  void decodeValue(uint8_t const* data) const override;
666  std::vector<uint8_t> encodeValue() const override;
667 
668  std::vector<std::string> toStringList() const override;
669 
670  private:
671  Asn1BooleanRecord() = default;
672 
673  mutable bool m_Value = false;
674  };
675 
679  {
680  friend class Asn1Record;
681 
682  public:
685 
686  protected:
687  void decodeValue(uint8_t const* data) const override
688  {}
689  std::vector<uint8_t> encodeValue() const override
690  {
691  return {};
692  }
693  };
694 
698  {
699  friend class Asn1ObjectIdentifierRecord;
700 
701  public:
705  explicit Asn1ObjectIdentifier(const uint8_t* data, size_t dataLen);
706 
710  explicit Asn1ObjectIdentifier(const std::string& oidString);
711 
713  const std::vector<uint32_t>& getComponents() const
714  {
715  return m_Components;
716  }
717 
720  bool operator==(const Asn1ObjectIdentifier& other) const
721  {
722  return m_Components == other.m_Components;
723  }
724 
727  bool operator!=(const Asn1ObjectIdentifier& other) const
728  {
729  return m_Components != other.m_Components;
730  }
731 
734  std::string toString() const;
735 
738  std::vector<uint8_t> toBytes() const;
739 
740  friend std::ostream& operator<<(std::ostream& os, const Asn1ObjectIdentifier& oid)
741  {
742  return os << oid.toString();
743  }
744 
745  protected:
746  Asn1ObjectIdentifier() = default;
747 
748  private:
749  std::vector<uint32_t> m_Components;
750  };
751 
755  {
756  friend class Asn1Record;
757 
758  public:
762 
765  {
766  decodeValueIfNeeded();
767  return m_Value;
768  }
769 
770  protected:
771  void decodeValue(uint8_t const* data) const override;
772  std::vector<uint8_t> encodeValue() const override;
773 
774  std::vector<std::string> toStringList() const override;
775 
776  private:
777  mutable Asn1ObjectIdentifier m_Value;
778 
779  Asn1ObjectIdentifierRecord() = default;
780  };
781 
786  {
787  public:
792  std::chrono::system_clock::time_point getValue(const std::string& timezone = "Z") const
793  {
794  decodeValueIfNeeded();
795  return adjustTimezones(m_Value, "Z", timezone);
796  };
797 
804  std::string getValueAsString(const std::string& format = "%Y-%m-%d %H:%M:%S", const std::string& timezone = "Z",
805  bool includeMilliseconds = false) const;
806 
807  protected:
808  Asn1TimeRecord() = default;
809  explicit Asn1TimeRecord(Asn1UniversalTagType tagType, const std::chrono::system_clock::time_point& value,
810  const std::string& timezone);
811 
812  mutable std::chrono::system_clock::time_point m_Value;
813 
814  std::vector<std::string> toStringList() const override;
815 
816  static void validateTimezone(const std::string& timezone);
817  static std::chrono::system_clock::time_point adjustTimezones(const std::chrono::system_clock::time_point& value,
818  const std::string& fromTimezone,
819  const std::string& toTimezone);
820  };
821 
825  {
826  friend class Asn1Record;
827 
828  public:
832  explicit Asn1UtcTimeRecord(const std::chrono::system_clock::time_point& value, bool withSeconds = true);
833 
834  protected:
835  void decodeValue(uint8_t const* data) const override;
836  std::vector<uint8_t> encodeValue() const override;
837 
838  private:
839  Asn1UtcTimeRecord() = default;
840  mutable bool m_WithSeconds = true;
841  };
842 
846  {
847  friend class Asn1Record;
848 
849  public:
855  explicit Asn1GeneralizedTimeRecord(const std::chrono::system_clock::time_point& value,
856  const std::string& timezone = "Z");
857 
858  protected:
859  void decodeValue(uint8_t const* data) const override;
860  std::vector<uint8_t> encodeValue() const override;
861 
862  private:
863  Asn1GeneralizedTimeRecord() = default;
864  mutable std::string m_Timezone;
865  };
866 
870  {
871  friend class Asn1Record;
872 
873  public:
877  explicit Asn1BitStringRecord(const std::string& value);
878 
880  std::string getValue()
881  {
882  decodeValueIfNeeded();
883  return m_Value.toString();
884  };
885 
887  std::vector<uint8_t> getVecValue()
888  {
889  decodeValueIfNeeded();
890  return m_Value.toBytes();
891  }
892 
893  protected:
894  void decodeValue(uint8_t const* data) const override;
895  std::vector<uint8_t> encodeValue() const override;
896 
897  std::vector<std::string> toStringList() const override;
898 
899  private:
900  class BitSet
901  {
902  public:
903  BitSet() = default;
904  explicit BitSet(const std::string& value);
905  BitSet(const uint8_t* data, size_t numBits);
906 
907  BitSet& operator=(const std::string& value);
908 
909  size_t sizeInBytes() const;
910  std::string toString() const;
911  std::vector<uint8_t> toBytes() const;
912  size_t getNumBits() const
913  {
914  return m_NumBits;
915  }
916 
917  private:
918  void initFromString(const std::string& value);
919 
920  std::vector<std::bitset<8>> m_Data;
921  size_t m_NumBits = 0;
922  };
923 
924  Asn1BitStringRecord() = default;
925 
926  mutable BitSet m_Value;
927  };
928 } // 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:870
std::string getValue()
Definition: Asn1Codec.h:880
std::vector< uint8_t > getVecValue()
Definition: Asn1Codec.h:887
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:649
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:658
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:517
Asn1EnumeratedRecord(uint32_t value)
Definition: Asn1Codec.h:846
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:633
Asn1IA5StringRecord(const std::string &value)
Definition: Asn1Codec.h:639
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:679
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:687
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:689
Asn1NullRecord()
A constructor to create a record of type Null.
Definition: Asn1Codec.h:698
std::vector< uint8_t > toBytes() const
bool operator==(const Asn1ObjectIdentifier &other) const
Definition: Asn1Codec.h:720
std::string toString() const
Asn1ObjectIdentifier(const uint8_t *data, size_t dataLen)
bool operator!=(const Asn1ObjectIdentifier &other) const
Definition: Asn1Codec.h:727
Asn1ObjectIdentifier(const std::string &oidString)
const std::vector< uint32_t > & getComponents() const
Definition: Asn1Codec.h:713
Definition: Asn1Codec.h:755
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:764
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:572
Asn1OctetStringRecord(const std::string &value)
Definition: Asn1Codec.h:585
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:617
Asn1PrintableStringRecord(const std::string &value)
Definition: Asn1Codec.h:623
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:533
std::string getValue() const
Definition: Asn1Codec.h:536
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:552
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:556
Definition: Asn1Codec.h:786
std::chrono::system_clock::time_point getValue(const std::string &timezone="Z") const
Definition: Asn1Codec.h:792
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:601
Asn1UTF8StringRecord(const std::string &value)
Definition: Asn1Codec.h:607
Definition: Asn1Codec.h:825
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.
@ PCPP_DEPRECATED
Deprecated typo, use OsiModelSessionLayer instead.
Definition: ProtocolType.h:432
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.