Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 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 | |
Ryan Hamilton | 7582d265 | 2018-08-01 22:35:32 | [diff] [blame] | 5 | #ifndef NET_QUIC_MOCK_DECRYPTER_H_ |
| 6 | #define NET_QUIC_MOCK_DECRYPTER_H_ |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 7 | |
| 8 | #include <cstddef> |
| 9 | #include <cstdint> |
| 10 | |
| 11 | #include "base/compiler_specific.h" |
| 12 | #include "base/macros.h" |
| 13 | #include "net/third_party/quic/core/crypto/quic_decrypter.h" |
| 14 | #include "net/third_party/quic/core/quic_types.h" |
| 15 | #include "net/third_party/quic/platform/api/quic_export.h" |
| 16 | #include "net/third_party/quic/platform/api/quic_string_piece.h" |
| 17 | |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame^] | 18 | namespace net { |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 19 | |
| 20 | // A MockDecrypter is a QuicDecrypter that does no validation of |
| 21 | // the given ciphertext and returns it untouched, ignoring the |
| 22 | // associated data. This is used to allow fuzzing to mutate |
| 23 | // plaintext packets. |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame^] | 24 | class MockDecrypter : public quic::QuicDecrypter { |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 25 | public: |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame^] | 26 | explicit MockDecrypter(quic::Perspective perspective); |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 27 | ~MockDecrypter() override {} |
| 28 | |
| 29 | // QuicDecrypter implementation |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame^] | 30 | bool SetKey(quic::QuicStringPiece key) override; |
| 31 | bool SetNoncePrefix(quic::QuicStringPiece nonce_prefix) override; |
| 32 | bool SetIV(quic::QuicStringPiece iv) override; |
| 33 | bool SetPreliminaryKey(quic::QuicStringPiece key) override; |
| 34 | bool SetDiversificationNonce( |
| 35 | const quic::DiversificationNonce& nonce) override; |
| 36 | bool DecryptPacket(quic::QuicTransportVersion version, |
| 37 | quic::QuicPacketNumber packet_number, |
| 38 | quic::QuicStringPiece associated_data, |
| 39 | quic::QuicStringPiece ciphertext, |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 40 | char* output, |
| 41 | size_t* output_length, |
| 42 | size_t max_output_length) override; |
| 43 | size_t GetKeySize() const override; |
| 44 | size_t GetIVSize() const override; |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame^] | 45 | quic::QuicStringPiece GetKey() const override; |
| 46 | quic::QuicStringPiece GetNoncePrefix() const override; |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 47 | |
| 48 | uint32_t cipher_id() const override; |
| 49 | |
| 50 | private: |
| 51 | DISALLOW_COPY_AND_ASSIGN(MockDecrypter); |
| 52 | }; |
| 53 | |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame^] | 54 | } // namespace net |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 55 | |
Ryan Hamilton | 7582d265 | 2018-08-01 22:35:32 | [diff] [blame] | 56 | #endif // NET_QUIC_MOCK_DECRYPTER_H_ |