Coverage Report

Created: 2026-12-01 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Packet++/header/QuicLayer.h
Line
Count
Source
1
#pragma once
2
#include "Layer.h"
3
#include "Packet.h"
4
#include <vector>
5
#include <string>
6
7
/// @file
8
9
/// @namespace pcpp
10
/// @brief The main namespace for the PcapPlusPlus lib
11
namespace pcpp
12
{
13
  /// @class QuicV1Layer
14
  /// Represents a QUIC v1 (RFC 9000/9001) protocol layer.
15
  class QuicV1Layer : public Layer
16
  {
17
  public:
18
    /// @enum QuicPacketType
19
    /// Identifies the kind of QUIC v1 packet, as carried by the Long Packet Type field for
20
    /// long-header packets (RFC 9000 Section 17.2), or inferred for short-header (1-RTT) and
21
    /// Version Negotiation packets, which don't carry this field on the wire
22
    enum class QuicPacketType : uint8_t
23
    {
24
      /// Initial packet - carries the start of the cryptographic handshake, plus an
25
      /// optional address-validation Token
26
      Initial = 0,
27
      /// 0-RTT packet - carries application data sent before the handshake completes
28
      ZeroRTT = 1,
29
      /// Handshake packet - carries the remainder of the cryptographic handshake
30
      Handshake = 2,
31
      /// Retry packet - sent by a server to perform address validation before committing
32
      /// state to a connection
33
      Retry = 3,
34
      /// Version Negotiation packet - sent by a server that doesn't support the client's
35
      /// requested QUIC version
36
      VersionNegotiation = 253,
37
      /// 1-RTT packet - a short-header packet carrying post-handshake application data
38
      OneRtt = 254,
39
    };
40
41
    /// @enum QuicHeaderForm
42
    /// Identifies whether a QUIC packet uses the long or short header form (RFC 9000 Section
43
    /// 17.2 vs. 17.3)
44
    enum class QuicHeaderForm : uint8_t
45
    {
46
      /// Short header - used for 1-RTT packets once the connection ID length is known out
47
      /// of band
48
      ShortHeader = 0,
49
      /// Long header - used for Initial, 0-RTT, Handshake, Retry and Version Negotiation
50
      /// packets, all of which are exchanged before that connection ID length is known
51
      LongHeader = 1
52
    };
53
54
    /// @struct ProtectedPayload
55
    /// A non-owning view of the protected portion of a QUIC packet
56
    struct ProtectedPayload
57
    {
58
      /// Pointer to the beginning of the protected data
59
      const uint8_t* data;
60
      /// Length of the protected data in bytes
61
      size_t length;
62
    };
63
64
    /// A static method that creates a QUIC v11 layer from packet raw data. Returns nullptr if
65
    /// data is not valid.
66
    /// @param[in] data A pointer to the raw data
67
    /// @param[in] dataLen Size of the data in bytes
68
    /// @param[in] prevLayer A pointer to the previous layer
69
    /// @param[in] packet A pointer to the Packet instance where layer will be stored
70
    /// @return The newly allocated layer or nullptr if the data isn't valid
71
    static QuicV1Layer* parseQuicLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
72
73
    /// @return The type of this QUIC packet
74
    virtual QuicPacketType getPacketType() const = 0;
75
76
    /// @return The header form (long or short) of this QUIC packet, as read straight off the
77
    /// wire
78
    QuicHeaderForm getHeaderForm() const;
79
80
    /// @return The value of the Fixed Bit field. Per RFC 9000 this is always 1
81
    uint8_t getFixedBit() const;
82
83
    /// A static method that checks whether the port is considered as QUIC
84
    /// @param[in] port The port number to be checked
85
    /// @return True if the port is considered as QUIC, false otherwise
86
    static bool isQuicPort(uint16_t port)
87
0
    {
88
0
      return port == 443;
89
0
    }
90
91
    // implement abstract methods
92
93
    /// Wraps any bytes remaining after this packet's header/payload as a subsequent
94
    /// QuicV1Layer if getHeaderLen() leaves data unconsumed - QUIC
95
    /// datagrams commonly coalesce multiple packets back to back - falling back to a
96
    /// PayloadLayer if what follows can't be parsed as QUIC
97
    void parseNextLayer() override;
98
99
    /// Does nothing for this layer
100
    void computeCalculateFields() override
101
0
    {}
102
103
    /// @return A string representation of the packet, e.g. "QUIC v1 Layer, Initial message"
104
    std::string toString() const override;
105
106
    /// @return @ref OsiModelTransportLayer
107
    OsiModelLayer getOsiModelLayer() const override
108
0
    {
109
0
      return OsiModelTransportLayer;
110
0
    }
111
112
    /// @struct SerializedFields
113
    /// Fields written by QuicV1Layer's serializeLayer(), in addition to Layer::SerializedFields
114
    struct SerializedFields : Layer::SerializedFields
115
    {
116
      /// @return All field descriptors for QuicV1Layer
117
      static std::vector<FieldDescriptor> all()
118
0
      {
119
0
        auto result = Layer::SerializedFields::all();
120
0
        std::initializer_list<FieldDescriptor> extra{ PacketType, HeaderForm, FixedBit };
121
0
        std::copy(extra.begin(), extra.end(), std::back_inserter(result));
122
0
        return result;
123
0
      }
124
125
      /// @brief Packet type name, e.g. "Initial" or "1-RTT" (the same names used by toString())
126
      static const FieldDescriptor PacketType;
127
      /// @brief Header form, as a string: "Long" or "Short"
128
      static const FieldDescriptor HeaderForm;
129
      /// @brief Value of the Fixed Bit, as an integer
130
      static const FieldDescriptor FixedBit;
131
132
      // cppcheck-suppress duplInheritedMember
133
      /// Maximum field ID used by the layer.
134
      static constexpr uint16_t MaxID = Layer::SerializedFields::MaxID + 3;
135
    };
136
137
  protected:
138
    void serializeLayer(ObjectScope& serializer) const override;
139
140
    QuicV1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
141
0
        : Layer(data, dataLen, prevLayer, packet, QUICv1)
142
0
    {}
143
144
    /// @struct quic_common_header
145
    /// The one-byte prefix shared by every QUIC v1 packet form, holding just the Header Form
146
    /// and Fixed Bit - enough to tell long-header and short-header packets apart before
147
    /// committing to either layout
148
    struct quic_common_header
149
    {
150
#if (BYTE_ORDER == LITTLE_ENDIAN)
151
      uint8_t : 6, fixedBit : 1, headerForm : 1;
152
#else
153
      uint8_t headerForm : 1, fixedBit : 1, : 6;
154
#endif
155
    };
156
157
#pragma pack(push, 1)
158
    /// @struct quic_long_header
159
    /// The fixed-size prefix of every long-header QUIC v1 packet (Initial, 0-RTT, Handshake,
160
    /// Retry and Version Negotiation): the common header byte, the 4-byte version, and the
161
    /// Destination Connection ID length. The variable-length fields that follow (DCID, SCID,
162
    /// Token, Length) are not part of this struct - they're read via pointer+length accessors
163
    /// on QuicV1LongHeaderLayer and its subclasses instead
164
    struct quic_long_header
165
    {
166
#if (BYTE_ORDER == LITTLE_ENDIAN)
167
      uint8_t packetNumberLength : 2, reserved : 2, longPacketType : 2, fixedBit : 1, headerForm : 1;
168
#else
169
      uint8_t headerForm : 1, fixedBit : 1, longPacketType : 2, reserved : 2, packetNumberLength : 2;
170
#endif
171
      uint32_t version;
172
      uint8_t destinationConnectionIdLength;
173
    };
174
#pragma pack(pop)
175
    static_assert(sizeof(quic_long_header) == 6, "quic_long_header size is not 6 bytes");
176
177
#pragma pack(push, 1)
178
    /// @struct quic_short_header
179
    /// The single-byte header of a 1-RTT (short-header) QUIC v1 packet. There is no
180
    /// Destination Connection ID length field here - a 1-RTT packet's connection ID has a
181
    /// length that's negotiated out of band during the handshake, so it can't be recovered
182
    /// from the packet alone
183
    struct quic_short_header
184
    {
185
#if (BYTE_ORDER == LITTLE_ENDIAN)
186
      uint8_t packetNumberLength : 2, keyPhase : 1, reserved : 2, spinBit : 1, fixedBit : 1, headerForm : 1;
187
#else
188
      uint8_t headerForm : 1, fixedBit : 1, spinBit : 1, reserved : 2, keyPhase : 1, packetNumberLength : 2;
189
#endif
190
    };
191
#pragma pack(pop)
192
    static_assert(sizeof(quic_short_header) == 1, "quic_short_header size is not 1 byte");
193
194
  private:
195
    quic_common_header* getCommonHeader() const
196
0
    {
197
0
      return reinterpret_cast<quic_common_header*>(m_Data);
198
0
    }
199
  };
200
201
  /// @class QuicV1LongHeaderLayer
202
  /// Base class for all QUIC v1 packet forms that use the long header (Initial, 0-RTT,
203
  /// Handshake, Retry and Version Negotiation). Provides parsing shared by all of them: the
204
  /// QUIC version and the Destination/Source Connection IDs, which sit at a fixed offset
205
  /// (Destination) or immediately after it (Source) in every long-header packet
206
  class QuicV1LongHeaderLayer : public QuicV1Layer
207
  {
208
  public:
209
    /// @return The packet type, read from the Long Packet Type field of the long header
210
    QuicPacketType getPacketType() const override;
211
212
    /// @return The QUIC version
213
    uint32_t getVersion() const;
214
215
    /// @return The Destination Connection ID, or an empty vector if the packet doesn't
216
    /// contain enough data to read it
217
    std::vector<uint8_t> getDestinationConnectionId() const;
218
219
    /// @return The Destination Connection ID as hex string, or an empty string if the packet doesn't
220
    /// contain enough data to read it
221
    std::string getDestinationConnectionIdAsString() const;
222
223
    /// @return The Source Connection ID, or an empty vector if the packet doesn't contain
224
    /// enough data to read it
225
    std::vector<uint8_t> getSourceConnectionId() const;
226
227
    /// @return The Source Connection ID as hex string, or an empty string if the packet doesn't contain
228
    /// enough data to read it
229
    std::string getSourceConnectionIdAsString() const;
230
231
    /// @struct SerializedFields
232
    /// Fields written by QuicV1LongHeaderLayer's serializeLayer(), in addition to QuicV1Layer::SerializedFields
233
    struct SerializedFields : QuicV1Layer::SerializedFields
234
    {
235
      /// @return All field descriptors for QuicV1LongHeaderLayer
236
      static std::vector<FieldDescriptor> all()
237
0
      {
238
0
        auto result = QuicV1Layer::SerializedFields::all();
239
0
        std::initializer_list<FieldDescriptor> extra{ Version, DestinationConnectionId, SourceConnectionId };
240
0
        std::copy(extra.begin(), extra.end(), std::back_inserter(result));
241
0
        return result;
242
0
      }
243
244
      /// @brief QUIC version in hexadecimal (host byte order)
245
      static const FieldDescriptor Version;
246
      /// @brief Destination Connection ID as a lowercase hex string, empty if it can't be read
247
      static const FieldDescriptor DestinationConnectionId;
248
      /// @brief Source Connection ID as a lowercase hex string, empty if it can't be read
249
      static const FieldDescriptor SourceConnectionId;
250
251
      // cppcheck-suppress duplInheritedMember
252
      /// Maximum field ID used by the layer.
253
      static constexpr uint16_t MaxID = QuicV1Layer::SerializedFields::MaxID + 3;
254
    };
255
256
  protected:
257
    void serializeLayer(ObjectScope& serializer) const override;
258
259
    using QuicV1Layer::QuicV1Layer;
260
261
    /// @struct OffsetAndLength
262
    /// The offset (from the start of the packet) and length, in bytes, of a variable-length
263
    /// field - used internally while walking the packet to locate the Source Connection ID,
264
    /// Token, and Length fields that follow the Destination Connection ID
265
    struct OffsetAndLength
266
    {
267
      /// The field's length, in bytes
268
      size_t length;
269
      /// The field's offset from the start of the packet, in bytes
270
      size_t offset;
271
272
      /// A constructor that creates an instance from a length and offset
273
      /// @param[in] length The field's length, in bytes
274
      /// @param[in] offset The field's offset from the start of the packet, in bytes
275
0
      OffsetAndLength(size_t length, size_t offset) : length(length), offset(offset)
276
0
      {}
277
    };
278
279
    OffsetAndLength getDestConIdOffsetAndLength() const;
280
281
    OffsetAndLength getSrcConIdOffsetAndLength() const;
282
283
  private:
284
    static constexpr int destinationConnectionIdOffset = sizeof(quic_long_header);
285
286
    static bool isDataValid(const uint8_t* data, size_t dataLen);
287
288
    quic_long_header* getLongHeader() const
289
0
    {
290
0
      return reinterpret_cast<quic_long_header*>(m_Data);
291
0
    }
292
293
    friend class QuicV1Layer;
294
  };
295
296
  /// @class QuicV1EstablishmentLayer
297
  /// Base class for the long-header packet forms that carry cryptographic handshake data and a
298
  /// Length field (Initial, 0-RTT and Handshake). Adds parsing of the QUIC variable-length
299
  /// integer ("varint") encoding (RFC 9000 Section 16) used for the Length field and, in
300
  /// QuicV1InitialLayer, the Token Length field as well
301
  class QuicV1EstablishmentLayer : public QuicV1LongHeaderLayer
302
  {
303
  public:
304
    /// @return The value of the Length field: the number of bytes in the Packet Number and
305
    /// Payload fields combined, or 0 if the packet doesn't contain enough data to read it
306
    uint64_t getLength() const;
307
308
    // implement abstract methods
309
310
    /// @return The header length, computed as the offset of the Length field plus the
311
    /// varint's own encoded size plus the value of the Length field itself, clamped to the
312
    /// amount of data actually captured
313
    size_t getHeaderLen() const override;
314
315
    /// Get the protected portion of the QUIC packet.
316
    /// The returned data points directly into the packet buffer and is not copied.
317
    /// This includes the Packet Number and the protected payload (including the AEAD authentication tag).
318
    /// @return A non-owning view of the protected portion of the packet
319
    ProtectedPayload getProtectedPayload() const;
320
321
    /// @struct SerializedFields
322
    /// Fields written by QuicV1EstablishmentLayer's serializeLayer(), in addition to
323
    /// QuicV1LongHeaderLayer::SerializedFields
324
    struct SerializedFields : QuicV1LongHeaderLayer::SerializedFields
325
    {
326
      /// @return All field descriptors for QuicV1EstablishmentLayer
327
      static std::vector<FieldDescriptor> all()
328
0
      {
329
0
        auto result = QuicV1LongHeaderLayer::SerializedFields::all();
330
0
        std::initializer_list<FieldDescriptor> extra{ PayloadLength };
331
0
        std::copy(extra.begin(), extra.end(), std::back_inserter(result));
332
0
        return result;
333
0
      }
334
335
      /// @brief Value of the Length field: the number of bytes in the Packet Number and Payload fields, or 0 if
336
      /// it can't be read
337
      static const FieldDescriptor PayloadLength;
338
339
      // cppcheck-suppress duplInheritedMember
340
      /// Maximum field ID used by the layer.
341
      static constexpr uint16_t MaxID = QuicV1LongHeaderLayer::SerializedFields::MaxID + 1;
342
    };
343
344
  protected:
345
    void serializeLayer(ObjectScope& serializer) const override;
346
347
    /// @struct VarintValueAndSize
348
    /// The decoded value of a QUIC variable-length integer, together with the number of
349
    /// bytes it occupied on the wire (1, 2, 4 or 8, per RFC 9000 Section 16) - returned by
350
    /// getVarintValueAndSize so callers can advance past the field without re-decoding
351
    /// its length
352
    struct VarintValueAndSize
353
    {
354
      /// The varint's decoded value
355
      uint64_t value;
356
      /// The varint's encoded size on the wire, in bytes (1, 2, 4 or 8)
357
      size_t size;
358
359
      /// A constructor that creates an instance from a decoded value and its encoded size
360
      /// @param[in] value The varint's decoded value
361
      /// @param[in] size The varint's encoded size on the wire, in bytes
362
0
      VarintValueAndSize(uint64_t value, size_t size) : value(value), size(size)
363
0
      {}
364
    };
365
366
    virtual size_t getLengthOffset() const;
367
368
    VarintValueAndSize getVarintValueAndSize(size_t offset) const;
369
370
  private:
371
    using QuicV1LongHeaderLayer::QuicV1LongHeaderLayer;
372
  };
373
374
  /// @class QuicV1InitialLayer
375
  /// Represents a QUIC v1 Initial packet - the first packet of a connection, carrying the
376
  /// start of the cryptographic handshake and, optionally, an address-validation Token
377
  /// (RFC 9000 Section 17.2.2)
378
  class QuicV1InitialLayer : public QuicV1EstablishmentLayer
379
  {
380
  public:
381
    /// @return The address-validation Token, or an empty vector if the packet carries no
382
    /// token or doesn't contain enough data to read it
383
    std::vector<uint8_t> getToken() const;
384
385
    /// @return The address-validation Token as hex string, or an empty string if the packet carries no
386
    /// token or doesn't contain enough data to read it
387
    std::string getTokenAsString() const;
388
389
    /// @struct SerializedFields
390
    /// Fields written by QuicV1InitialLayer's serializeLayer(), in addition to
391
    /// QuicV1EstablishmentLayer::SerializedFields
392
    struct SerializedFields : QuicV1EstablishmentLayer::SerializedFields
393
    {
394
      /// @return All field descriptors for QuicV1InitialLayer
395
      static std::vector<FieldDescriptor> all()
396
0
      {
397
0
        auto result = QuicV1EstablishmentLayer::SerializedFields::all();
398
0
        std::initializer_list<FieldDescriptor> extra{ Token };
399
0
        std::copy(extra.begin(), extra.end(), std::back_inserter(result));
400
0
        return result;
401
0
      }
402
403
      /// @brief Address-validation Token as a lowercase hex string, empty if there is none
404
      static const FieldDescriptor Token;
405
406
      // cppcheck-suppress duplInheritedMember
407
      /// Maximum field ID used by the layer.
408
      static constexpr uint16_t MaxID = QuicV1EstablishmentLayer::SerializedFields::MaxID + 1;
409
    };
410
411
  protected:
412
    void serializeLayer(ObjectScope& serializer) const override;
413
414
  private:
415
    using QuicV1EstablishmentLayer::QuicV1EstablishmentLayer;
416
417
    size_t getLengthOffset() const override;
418
419
    size_t getTokenLengthOffset() const;
420
421
    friend class QuicV1Layer;
422
  };
423
424
  /// @class QuicV1ZeroRttLayer
425
  /// Represents a QUIC v1 0-RTT packet - carries application data sent before the
426
  /// cryptographic handshake completes (RFC 9000 Section 17.2.3). Adds no parsing beyond what
427
  /// QuicV1EstablishmentLayer already provides
428
  class QuicV1ZeroRttLayer : public QuicV1EstablishmentLayer
429
  {
430
    using QuicV1EstablishmentLayer::QuicV1EstablishmentLayer;
431
432
    friend class QuicV1Layer;
433
  };
434
435
  /// @class QuicV1HandshakeLayer
436
  /// Represents a QUIC v1 Handshake packet - carries the remainder of the cryptographic
437
  /// handshake after the Initial packet (RFC 9000 Section 17.2.4). Adds no parsing beyond what
438
  /// QuicV1EstablishmentLayer already provides
439
  class QuicV1HandshakeLayer : public QuicV1EstablishmentLayer
440
  {
441
    using QuicV1EstablishmentLayer::QuicV1EstablishmentLayer;
442
443
    friend class QuicV1Layer;
444
  };
445
446
  /// @class QuicV1RetryLayer
447
  /// Represents a QUIC v1 Retry packet - sent by a server to perform address validation before
448
  /// committing state to a connection (RFC 9000 Section 17.2.5). Carries a Retry Token and,
449
  /// unlike the other long-header forms, a fixed-size 16-byte integrity tag rather than a
450
  /// varint-prefixed Length field
451
  class QuicV1RetryLayer : public QuicV1LongHeaderLayer
452
  {
453
  public:
454
    /// @return The Retry Token, or an empty vector if the packet doesn't contain enough
455
    /// data - beyond the Source Connection ID - to also hold the 16-byte integrity tag
456
    std::vector<uint8_t> getRetryToken() const;
457
458
    /// @return The Retry Token as hex string, or an empty string if the packet doesn't contain enough
459
    /// data - beyond the Source Connection ID - to also hold the 16-byte integrity tag
460
    std::string getRetryTokenAsString() const;
461
462
    /// @return The 16-byte Retry Integrity Tag, or an empty vector if the packet doesn't
463
    /// contain enough data - beyond the Source Connection ID - to hold it
464
    std::vector<uint8_t> getRetryIntegrityTag() const;
465
466
    /// @return The 16-byte Retry Integrity Tag as hex string, or an empty string if the packet doesn't
467
    /// contain enough data - beyond the Source Connection ID - to hold it
468
    std::string getRetryIntegrityTagAsString() const;
469
470
    // implement abstract methods
471
472
    /// @return sizeof(m_DataLen) - a Retry packet has no Length field, so its header is
473
    /// considered to span the entire packet
474
    size_t getHeaderLen() const override
475
0
    {
476
0
      return m_DataLen;
477
0
    }
478
479
    /// @struct SerializedFields
480
    /// Fields written by QuicV1RetryLayer's serializeLayer(), in addition to
481
    /// QuicV1LongHeaderLayer::SerializedFields
482
    struct SerializedFields : QuicV1LongHeaderLayer::SerializedFields
483
    {
484
      /// @return All field descriptors for QuicV1RetryLayer
485
      static std::vector<FieldDescriptor> all()
486
0
      {
487
0
        auto result = QuicV1LongHeaderLayer::SerializedFields::all();
488
0
        std::initializer_list<FieldDescriptor> extra{ RetryToken, RetryIntegrityTag };
489
0
        std::copy(extra.begin(), extra.end(), std::back_inserter(result));
490
0
        return result;
491
0
      }
492
493
      /// @brief Retry Token as a lowercase hex string
494
      static const FieldDescriptor RetryToken;
495
      /// @brief Retry Integrity Tag as a lowercase hex string, empty if it can't be read
496
      static const FieldDescriptor RetryIntegrityTag;
497
498
      // cppcheck-suppress duplInheritedMember
499
      /// Maximum field ID used by the layer.
500
      static constexpr uint16_t MaxID = QuicV1LongHeaderLayer::SerializedFields::MaxID + 2;
501
    };
502
503
  protected:
504
    void serializeLayer(ObjectScope& serializer) const override;
505
506
  private:
507
    using QuicV1LongHeaderLayer::QuicV1LongHeaderLayer;
508
509
    static constexpr size_t retryIntegritySize = 16;
510
511
    size_t getRetryTokenOffset() const;
512
513
    friend class QuicV1Layer;
514
  };
515
516
  /// @class QuicV1VersionNegotiationLayer
517
  /// Represents a QUIC Version Negotiation packet - sent by a server that doesn't support the
518
  /// QUIC version a client requested, listing the versions it does support (RFC 9000 Section
519
  /// 17.2.1). Identified by a version field of 0 rather than a Long Packet Type value, so
520
  /// getPacketType() always returns QuicPacketType::VersionNegotiation
521
  class QuicV1VersionNegotiationLayer : public QuicV1LongHeaderLayer
522
  {
523
  public:
524
    /// @return QuicPacketType::VersionNegotiation
525
    QuicPacketType getPacketType() const override
526
0
    {
527
0
      return QuicPacketType::VersionNegotiation;
528
0
    }
529
530
    /// @return The list of QUIC versions the server supports, in host byte order. Returns
531
    /// an empty list if a trailing partial version is encountered
532
    std::vector<uint32_t> getSupportedVersions() const;
533
534
    // implement abstract methods
535
536
    /// @return sizeof(m_DataLen) - a Version Negotiation packet has no further layers beyond
537
    /// the list of supported versions, so its header is considered to span the entire packet
538
    size_t getHeaderLen() const override
539
0
    {
540
0
      return m_DataLen;
541
0
    }
542
543
    /// @struct SerializedFields
544
    /// Fields written by QuicV1VersionNegotiationLayer's serializeLayer(), in addition to
545
    /// QuicV1LongHeaderLayer::SerializedFields
546
    struct SerializedFields : QuicV1LongHeaderLayer::SerializedFields
547
    {
548
      /// @return All field descriptors for QuicV1VersionNegotiationLayer
549
      static std::vector<FieldDescriptor> all()
550
0
      {
551
0
        auto result = QuicV1LongHeaderLayer::SerializedFields::all();
552
0
        std::initializer_list<FieldDescriptor> extra{ SupportedVersions };
553
0
        std::copy(extra.begin(), extra.end(), std::back_inserter(result));
554
0
        return result;
555
0
      }
556
557
      /// @brief List of supported versions
558
      static const FieldDescriptor SupportedVersions;
559
      /// @brief A single supported version in hexadecimal (host byte order)
560
      static const FieldDescriptor SupportedVersion;
561
562
      // cppcheck-suppress duplInheritedMember
563
      /// Maximum field ID used by the layer.
564
      static constexpr uint16_t MaxID = QuicV1LongHeaderLayer::SerializedFields::MaxID + 1;
565
    };
566
567
  protected:
568
    void serializeLayer(ObjectScope& serializer) const override;
569
570
  private:
571
    using QuicV1LongHeaderLayer::QuicV1LongHeaderLayer;
572
573
    friend class QuicV1Layer;
574
  };
575
576
  /// @class QuicV1OneRttLayer
577
  /// Represents a QUIC v1 1-RTT packet - a short-header packet carrying post-handshake
578
  /// application data (RFC 9000 Section 17.3.1). Since the short header carries no explicit
579
  /// Length field, getHeaderLen() treats the header as spanning the entire packet
580
  class QuicV1OneRttLayer : public QuicV1Layer
581
  {
582
  public:
583
    /// @return QuicPacketType::OneRtt
584
    QuicPacketType getPacketType() const override
585
0
    {
586
0
      return QuicPacketType::OneRtt;
587
0
    }
588
589
    /// @return The value of the Spin Bit, used for passive latency measurement along the
590
    /// connection's path
591
    bool getSpinBit() const
592
0
    {
593
0
      return getShortHeader()->spinBit;
594
0
    }
595
596
    /// @return The value of the Key Phase bit, used to identify which packet protection keys
597
    /// were used to protect this packet
598
    bool getKeyPhaseBit() const
599
0
    {
600
0
      return getShortHeader()->keyPhase;
601
0
    }
602
603
    /// Get the protected portion of the QUIC packet.
604
    /// The returned data points directly into the packet buffer and is not copied.
605
    /// @return A non-owning view of the protected portion of the packet
606
    ProtectedPayload getProtectedPayload() const;
607
608
    // implement abstract methods
609
610
    /// @return sizeof(m_DataLen) - a 1-RTT packet's short header carries no Length field, so
611
    /// its header is considered to span the entire packet
612
    size_t getHeaderLen() const override
613
0
    {
614
0
      return m_DataLen;
615
0
    }
616
617
    /// @struct SerializedFields
618
    /// Fields written by QuicV1OneRttLayer's serializeLayer(), in addition to QuicV1Layer::SerializedFields
619
    struct SerializedFields : QuicV1Layer::SerializedFields
620
    {
621
      /// @return All field descriptors for QuicV1OneRttLayer
622
      static std::vector<FieldDescriptor> all()
623
0
      {
624
0
        auto result = QuicV1Layer::SerializedFields::all();
625
0
        std::initializer_list<FieldDescriptor> extra{ SpinBit, KeyPhaseBit };
626
0
        std::copy(extra.begin(), extra.end(), std::back_inserter(result));
627
0
        return result;
628
0
      }
629
630
      /// @brief Latency Spin Bit, as a boolean
631
      static const FieldDescriptor SpinBit;
632
      /// @brief Key Phase bit, as a boolean
633
      static const FieldDescriptor KeyPhaseBit;
634
635
      // cppcheck-suppress duplInheritedMember
636
      /// Maximum field ID used by the layer.
637
      static constexpr uint16_t MaxID = QuicV1Layer::SerializedFields::MaxID + 2;
638
    };
639
640
  protected:
641
    void serializeLayer(ObjectScope& serializer) const override;
642
643
  private:
644
    using QuicV1Layer::QuicV1Layer;
645
646
    static bool isDataValid(const uint8_t* data, size_t dataLen);
647
648
    quic_short_header* getShortHeader() const
649
0
    {
650
0
      return reinterpret_cast<quic_short_header*>(m_Data);
651
0
    }
652
653
    friend class QuicV1Layer;
654
  };
655
}  // namespace pcpp