summaryrefslogtreecommitdiff
path: root/chromium/net/third_party/quiche/src/quic/test_tools/test_ticket_crypter.h
blob: 63919c61bbac644025188b1094b08c2051db8206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef QUICHE_QUIC_TEST_TOOLS_TEST_TICKET_CRYPTER_H_
#define QUICHE_QUIC_TEST_TOOLS_TEST_TICKET_CRYPTER_H_

#include "quic/core/crypto/proof_source.h"

namespace quic {
namespace test {

// Provides a simple implementation of ProofSource::TicketCrypter for testing.
// THIS IMPLEMENTATION IS NOT SECURE. It is only intended for testing purposes.
class TestTicketCrypter : public ProofSource::TicketCrypter {
 public:
  TestTicketCrypter();
  ~TestTicketCrypter() override = default;

  // TicketCrypter interface
  size_t MaxOverhead() override;
  std::vector<uint8_t> Encrypt(absl::string_view in) override;
  void Decrypt(absl::string_view in,
               std::unique_ptr<ProofSource::DecryptCallback> callback) override;

  void SetRunCallbacksAsync(bool run_async);
  size_t NumPendingCallbacks();
  void RunPendingCallback(size_t n);

  // Allows configuring this TestTicketCrypter to fail decryption.
  void set_fail_decrypt(bool fail_decrypt) { fail_decrypt_ = fail_decrypt; }

 private:
  // Performs the Decrypt operation synchronously.
  std::vector<uint8_t> Decrypt(absl::string_view in);

  struct PendingCallback {
    std::unique_ptr<ProofSource::DecryptCallback> callback;
    std::vector<uint8_t> decrypted_ticket;
  };

  bool fail_decrypt_ = false;
  bool run_async_ = false;
  std::vector<PendingCallback> pending_callbacks_;
  std::vector<uint8_t> ticket_prefix_;
};

}  // namespace test
}  // namespace quic

#endif  // QUICHE_QUIC_TEST_TOOLS_TEST_TICKET_CRYPTER_H_