• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Authors
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 NET_QUIC_MOCK_ENCRYPTER_H_
6 #define NET_QUIC_MOCK_ENCRYPTER_H_
7 
8 #include <cstddef>
9 #include <limits>
10 
11 #include "base/compiler_specific.h"
12 #include "net/base/net_export.h"
13 #include "net/third_party/quiche/src/quiche/quic/core/crypto/quic_encrypter.h"
14 #include "net/third_party/quiche/src/quiche/quic/core/quic_types.h"
15 
16 namespace net {
17 
18 // A MockEncrypter is a QuicEncrypter that returns this plaintext followed by 12
19 // bytes of zeroes. No encryption or MAC is applied. This is used to allow
20 // fuzzing to mutate plaintext packets.
21 class MockEncrypter : public quic::QuicEncrypter {
22  public:
23   explicit MockEncrypter(quic::Perspective perspective);
24 
25   MockEncrypter(const MockEncrypter&) = delete;
26   MockEncrypter& operator=(const MockEncrypter&) = delete;
27 
28   ~MockEncrypter() override = default;
29 
30   // QuicEncrypter implementation
31   bool SetKey(absl::string_view key) override;
32   bool SetNoncePrefix(absl::string_view nonce_prefix) override;
33   bool SetHeaderProtectionKey(absl::string_view key) override;
34   bool SetIV(absl::string_view iv) override;
35   bool EncryptPacket(uint64_t packet_number,
36                      absl::string_view associated_data,
37                      absl::string_view plaintext,
38                      char* output,
39                      size_t* output_length,
40                      size_t max_output_length) override;
41   std::string GenerateHeaderProtectionMask(absl::string_view sample) override;
42   size_t GetKeySize() const override;
43   size_t GetNoncePrefixSize() const override;
44   size_t GetIVSize() const override;
45   size_t GetMaxPlaintextSize(size_t ciphertext_size) const override;
46   size_t GetCiphertextSize(size_t plaintext_size) const override;
47   quic::QuicPacketCount GetConfidentialityLimit() const override;
48   absl::string_view GetKey() const override;
49   absl::string_view GetNoncePrefix() const override;
50 };
51 
52 }  // namespace net
53 
54 #endif  // NET_QUIC_MOCK_ENCRYPTER_H_
55