xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/frames/quic_crypto_frame.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef QUICHE_QUIC_CORE_FRAMES_QUIC_CRYPTO_FRAME_H_
6 #define QUICHE_QUIC_CORE_FRAMES_QUIC_CRYPTO_FRAME_H_
7 
8 #include <memory>
9 #include <ostream>
10 
11 #include "absl/strings/string_view.h"
12 #include "quiche/quic/core/quic_types.h"
13 #include "quiche/quic/platform/api/quic_export.h"
14 
15 namespace quic {
16 
17 struct QUICHE_EXPORT QuicCryptoFrame {
18   QuicCryptoFrame() = default;
19   QuicCryptoFrame(EncryptionLevel level, QuicStreamOffset offset,
20                   QuicPacketLength data_length);
21   QuicCryptoFrame(EncryptionLevel level, QuicStreamOffset offset,
22                   absl::string_view data);
23   ~QuicCryptoFrame();
24 
25   friend QUICHE_EXPORT std::ostream& operator<<(std::ostream& os,
26                                                 const QuicCryptoFrame& s);
27 
28   // TODO(haoyuewang) Consider replace the EncryptionLevel here with
29   // PacketNumberSpace.
30   // When writing a crypto frame to a packet, the packet must be encrypted at
31   // |level|. When a crypto frame is read, the encryption level of the packet it
32   // was received in is put in |level|.
33   EncryptionLevel level = ENCRYPTION_INITIAL;
34   QuicPacketLength data_length = 0;
35   // When reading, |data_buffer| points to the data that was received in the
36   // frame. |data_buffer| is not used when writing.
37   const char* data_buffer = nullptr;
38   QuicStreamOffset offset = 0;  // Location of this data in the stream.
39 
40   QuicCryptoFrame(EncryptionLevel level, QuicStreamOffset offset,
41                   const char* data_buffer, QuicPacketLength data_length);
42 };
43 static_assert(sizeof(QuicCryptoFrame) <= 64,
44               "Keep the QuicCryptoFrame size to a cacheline.");
45 
46 }  // namespace quic
47 
48 #endif  // QUICHE_QUIC_CORE_FRAMES_QUIC_CRYPTO_FRAME_H_
49