mock_encrypter.h 2.0 KB

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