93 lines
2.3 KiB
C++
93 lines
2.3 KiB
C++
|
|
// Copyright 2017 The Chromium Authors
|
||
|
|
// Use of this source code is governed by a BSD-style license that can be
|
||
|
|
// found in the LICENSE file.
|
||
|
|
|
||
|
|
#include "net/quic/mock_encrypter.h"
|
||
|
|
|
||
|
|
#include "net/third_party/quiche/src/quiche/quic/core/quic_data_writer.h"
|
||
|
|
#include "net/third_party/quiche/src/quiche/quic/core/quic_utils.h"
|
||
|
|
|
||
|
|
using quic::DiversificationNonce;
|
||
|
|
using quic::Perspective;
|
||
|
|
using quic::QuicPacketNumber;
|
||
|
|
|
||
|
|
namespace net {
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
|
||
|
|
const size_t kPaddingSize = 12;
|
||
|
|
|
||
|
|
} // namespace
|
||
|
|
|
||
|
|
MockEncrypter::MockEncrypter(Perspective perspective) {}
|
||
|
|
|
||
|
|
bool MockEncrypter::SetKey(absl::string_view key) {
|
||
|
|
return key.empty();
|
||
|
|
}
|
||
|
|
|
||
|
|
bool MockEncrypter::SetNoncePrefix(absl::string_view nonce_prefix) {
|
||
|
|
return nonce_prefix.empty();
|
||
|
|
}
|
||
|
|
|
||
|
|
bool MockEncrypter::SetIV(absl::string_view iv) {
|
||
|
|
return iv.empty();
|
||
|
|
}
|
||
|
|
|
||
|
|
bool MockEncrypter::EncryptPacket(uint64_t /*packet_number*/,
|
||
|
|
absl::string_view associated_data,
|
||
|
|
absl::string_view plaintext,
|
||
|
|
char* output,
|
||
|
|
size_t* output_length,
|
||
|
|
size_t max_output_length) {
|
||
|
|
size_t ciphertext_size = plaintext.size() + kPaddingSize;
|
||
|
|
if (max_output_length < ciphertext_size) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
memcpy(output, plaintext.data(), ciphertext_size);
|
||
|
|
*output_length = ciphertext_size;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool MockEncrypter::SetHeaderProtectionKey(absl::string_view key) {
|
||
|
|
return key.empty();
|
||
|
|
}
|
||
|
|
|
||
|
|
std::string MockEncrypter::GenerateHeaderProtectionMask(
|
||
|
|
absl::string_view sample) {
|
||
|
|
return std::string(5, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
size_t MockEncrypter::GetKeySize() const {
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
size_t MockEncrypter::GetNoncePrefixSize() const {
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
size_t MockEncrypter::GetIVSize() const {
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
size_t MockEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const {
|
||
|
|
return ciphertext_size - kPaddingSize;
|
||
|
|
}
|
||
|
|
|
||
|
|
size_t MockEncrypter::GetCiphertextSize(size_t plaintext_size) const {
|
||
|
|
return plaintext_size + kPaddingSize;
|
||
|
|
}
|
||
|
|
|
||
|
|
quic::QuicPacketCount MockEncrypter::GetConfidentialityLimit() const {
|
||
|
|
return std::numeric_limits<quic::QuicPacketCount>::max();
|
||
|
|
}
|
||
|
|
|
||
|
|
absl::string_view MockEncrypter::GetKey() const {
|
||
|
|
return absl::string_view();
|
||
|
|
}
|
||
|
|
|
||
|
|
absl::string_view MockEncrypter::GetNoncePrefix() const {
|
||
|
|
return absl::string_view();
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace net
|