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