mock_decrypter.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_DECRYPTER_H_
  5. #define NET_QUIC_MOCK_DECRYPTER_H_
  6. #include <cstddef>
  7. #include <cstdint>
  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_decrypter.h"
  11. #include "net/third_party/quiche/src/quiche/quic/core/quic_types.h"
  12. namespace net {
  13. // A MockDecrypter is a QuicDecrypter that strips the last 12 bytes of
  14. // ciphertext (which should be zeroes, but are ignored), and returns the
  15. // remaining ciphertext untouched and ignores the associated data. This is used
  16. // to allow fuzzing to mutate plaintext packets.
  17. class MockDecrypter : public quic::QuicDecrypter {
  18. public:
  19. explicit MockDecrypter(quic::Perspective perspective);
  20. MockDecrypter(const MockDecrypter&) = delete;
  21. MockDecrypter& operator=(const MockDecrypter&) = delete;
  22. ~MockDecrypter() override = default;
  23. // QuicCrypter implementation
  24. bool SetKey(absl::string_view key) override;
  25. bool SetNoncePrefix(absl::string_view nonce_prefix) override;
  26. bool SetIV(absl::string_view iv) override;
  27. bool SetHeaderProtectionKey(absl::string_view key) override;
  28. size_t GetKeySize() const override;
  29. size_t GetIVSize() const override;
  30. size_t GetNoncePrefixSize() const override;
  31. // QuicDecrypter implementation
  32. bool SetPreliminaryKey(absl::string_view key) override;
  33. bool SetDiversificationNonce(
  34. const quic::DiversificationNonce& nonce) override;
  35. bool DecryptPacket(uint64_t packet_number,
  36. absl::string_view associated_data,
  37. absl::string_view ciphertext,
  38. char* output,
  39. size_t* output_length,
  40. size_t max_output_length) override;
  41. std::string GenerateHeaderProtectionMask(
  42. quic::QuicDataReader* sample_reader) override;
  43. uint32_t cipher_id() const override;
  44. quic::QuicPacketCount GetIntegrityLimit() const override;
  45. absl::string_view GetKey() const override;
  46. absl::string_view GetNoncePrefix() const override;
  47. };
  48. } // namespace net
  49. #endif // NET_QUIC_MOCK_DECRYPTER_H_