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 #include "net/quic/mock_encrypter.h"
6
7 #include "net/third_party/quiche/src/quiche/quic/core/quic_data_writer.h"
8 #include "net/third_party/quiche/src/quiche/quic/core/quic_utils.h"
9
10 using quic::DiversificationNonce;
11 using quic::Perspective;
12 using quic::QuicPacketNumber;
13
14 namespace net {
15
16 namespace {
17
18 const size_t kPaddingSize = 12;
19
20 } // namespace
21
MockEncrypter(Perspective perspective)22 MockEncrypter::MockEncrypter(Perspective perspective) {}
23
SetKey(absl::string_view key)24 bool MockEncrypter::SetKey(absl::string_view key) {
25 return key.empty();
26 }
27
SetNoncePrefix(absl::string_view nonce_prefix)28 bool MockEncrypter::SetNoncePrefix(absl::string_view nonce_prefix) {
29 return nonce_prefix.empty();
30 }
31
SetIV(absl::string_view iv)32 bool MockEncrypter::SetIV(absl::string_view iv) {
33 return iv.empty();
34 }
35
EncryptPacket(uint64_t,absl::string_view associated_data,absl::string_view plaintext,char * output,size_t * output_length,size_t max_output_length)36 bool MockEncrypter::EncryptPacket(uint64_t /*packet_number*/,
37 absl::string_view associated_data,
38 absl::string_view plaintext,
39 char* output,
40 size_t* output_length,
41 size_t max_output_length) {
42 size_t ciphertext_size = plaintext.size() + kPaddingSize;
43 if (max_output_length < ciphertext_size) {
44 return false;
45 }
46 memcpy(output, plaintext.data(), ciphertext_size);
47 *output_length = ciphertext_size;
48 return true;
49 }
50
SetHeaderProtectionKey(absl::string_view key)51 bool MockEncrypter::SetHeaderProtectionKey(absl::string_view key) {
52 return key.empty();
53 }
54
GenerateHeaderProtectionMask(absl::string_view sample)55 std::string MockEncrypter::GenerateHeaderProtectionMask(
56 absl::string_view sample) {
57 return std::string(5, 0);
58 }
59
GetKeySize() const60 size_t MockEncrypter::GetKeySize() const {
61 return 0;
62 }
63
GetNoncePrefixSize() const64 size_t MockEncrypter::GetNoncePrefixSize() const {
65 return 0;
66 }
67
GetIVSize() const68 size_t MockEncrypter::GetIVSize() const {
69 return 0;
70 }
71
GetMaxPlaintextSize(size_t ciphertext_size) const72 size_t MockEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const {
73 return ciphertext_size - kPaddingSize;
74 }
75
GetCiphertextSize(size_t plaintext_size) const76 size_t MockEncrypter::GetCiphertextSize(size_t plaintext_size) const {
77 return plaintext_size + kPaddingSize;
78 }
79
GetConfidentialityLimit() const80 quic::QuicPacketCount MockEncrypter::GetConfidentialityLimit() const {
81 return std::numeric_limits<quic::QuicPacketCount>::max();
82 }
83
GetKey() const84 absl::string_view MockEncrypter::GetKey() const {
85 return absl::string_view();
86 }
87
GetNoncePrefix() const88 absl::string_view MockEncrypter::GetNoncePrefix() const {
89 return absl::string_view();
90 }
91
92 } // namespace net
93