Use quiche string libraries in third_party/quic/core
gfe-relnote: n/a, no functional change
PiperOrigin-RevId: 285401547
Change-Id: Ice6d421ff7058fe2d47aee426d7634b6d403ee3f
diff --git a/quic/core/quic_framer.cc b/quic/core/quic_framer.cc
index 3235009..678796c 100644
--- a/quic/core/quic_framer.cc
+++ b/quic/core/quic_framer.cc
@@ -41,8 +41,9 @@
#include "net/third_party/quiche/src/quic/platform/api/quic_logging.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_map_util.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_stack_trace.h"
-#include "net/third_party/quiche/src/quic/platform/api/quic_str_cat.h"
-#include "net/third_party/quiche/src/quic/platform/api/quic_text_utils.h"
+#include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h"
+#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
+#include "net/third_party/quiche/src/common/platform/api/quiche_text_utils.h"
namespace quic {
@@ -292,14 +293,14 @@
return NUM_ENCRYPTION_LEVELS;
}
-QuicStringPiece TruncateErrorString(QuicStringPiece error) {
+quiche::QuicheStringPiece TruncateErrorString(quiche::QuicheStringPiece error) {
if (error.length() <= kMaxErrorStringLength) {
return error;
}
- return QuicStringPiece(error.data(), kMaxErrorStringLength);
+ return quiche::QuicheStringPiece(error.data(), kMaxErrorStringLength);
}
-size_t TruncatedErrorStringSize(const QuicStringPiece& error) {
+size_t TruncatedErrorStringSize(const quiche::QuicheStringPiece& error) {
if (error.length() < kMaxErrorStringLength) {
return error.length();
}
@@ -384,8 +385,9 @@
// the error value in the string.
return initial_error_string;
}
- return QuicStrCat(std::to_string(static_cast<unsigned>(quic_error_code)), ":",
- initial_error_string);
+ return quiche::QuicheStrCat(
+ std::to_string(static_cast<unsigned>(quic_error_code)), ":",
+ initial_error_string);
}
} // namespace
@@ -1516,7 +1518,7 @@
return false;
}
- QuicStringPiece retry_token = reader->ReadRemainingPayload();
+ quiche::QuicheStringPiece retry_token = reader->ReadRemainingPayload();
visitor_->OnRetryPacket(original_destination_connection_id,
header.source_connection_id, retry_token);
return true;
@@ -1534,7 +1536,8 @@
return;
}
- QuicStringPiece remaining_data = encrypted_reader.PeekRemainingPayload();
+ quiche::QuicheStringPiece remaining_data =
+ encrypted_reader.PeekRemainingPayload();
DCHECK_EQ(remaining_data.length(), remaining_bytes_length);
const char* coalesced_data =
@@ -1548,8 +1551,8 @@
QUIC_PEER_BUG << ENDPOINT
<< "Failed to parse received coalesced header of length "
<< coalesced_data_length << ": "
- << QuicTextUtils::HexEncode(coalesced_data,
- coalesced_data_length)
+ << quiche::QuicheTextUtils::HexEncode(coalesced_data,
+ coalesced_data_length)
<< " previous header was " << header;
return;
}
@@ -1612,7 +1615,8 @@
perspective_ == Perspective::IS_CLIENT) {
// Peek possible stateless reset token. Will only be used on decryption
// failure.
- QuicStringPiece remaining = encrypted_reader->PeekRemainingPayload();
+ quiche::QuicheStringPiece remaining =
+ encrypted_reader->PeekRemainingPayload();
if (remaining.length() >= sizeof(header->possible_stateless_reset_token)) {
header->has_possible_stateless_reset_token = true;
memcpy(&header->possible_stateless_reset_token,
@@ -1626,7 +1630,7 @@
return false;
}
- QuicStringPiece associated_data;
+ quiche::QuicheStringPiece associated_data;
std::vector<char> ad_storage;
if (header->form == IETF_QUIC_SHORT_HEADER_PACKET ||
header->long_packet_type != VERSION_NEGOTIATION) {
@@ -1652,7 +1656,8 @@
&full_packet_number, &ad_storage)) {
hp_removal_failed = true;
}
- associated_data = QuicStringPiece(ad_storage.data(), ad_storage.size());
+ associated_data =
+ quiche::QuicheStringPiece(ad_storage.data(), ad_storage.size());
} else if (!ProcessAndCalculatePacketNumber(
encrypted_reader, header->packet_number_length,
base_packet_number, &full_packet_number)) {
@@ -1712,7 +1717,8 @@
return false;
}
- QuicStringPiece encrypted = encrypted_reader->ReadRemainingPayload();
+ quiche::QuicheStringPiece encrypted =
+ encrypted_reader->ReadRemainingPayload();
if (!version_.HasHeaderProtection()) {
associated_data = GetAssociatedDataFromEncryptedPacket(
version_.transport_version, packet,
@@ -1808,14 +1814,16 @@
return false;
}
- QuicStringPiece encrypted = encrypted_reader->ReadRemainingPayload();
- QuicStringPiece associated_data = GetAssociatedDataFromEncryptedPacket(
- version_.transport_version, packet,
- GetIncludedDestinationConnectionIdLength(*header),
- GetIncludedSourceConnectionIdLength(*header), header->version_flag,
- header->nonce != nullptr, header->packet_number_length,
- header->retry_token_length_length, header->retry_token.length(),
- header->length_length);
+ quiche::QuicheStringPiece encrypted =
+ encrypted_reader->ReadRemainingPayload();
+ quiche::QuicheStringPiece associated_data =
+ GetAssociatedDataFromEncryptedPacket(
+ version_.transport_version, packet,
+ GetIncludedDestinationConnectionIdLength(*header),
+ GetIncludedSourceConnectionIdLength(*header), header->version_flag,
+ header->nonce != nullptr, header->packet_number_length,
+ header->retry_token_length_length, header->retry_token.length(),
+ header->length_length);
size_t decrypted_length = 0;
EncryptionLevel decrypted_level;
@@ -1893,7 +1901,7 @@
}
// TODO(satyamshekhar): validate nonce to protect against DoS.
- QuicStringPiece address;
+ quiche::QuicheStringPiece address;
if (reset->GetStringPiece(kCADR, &address)) {
QuicSocketAddressCoder address_coder;
if (address_coder.Decode(address.data(), address.length())) {
@@ -1902,7 +1910,7 @@
}
}
- QuicStringPiece endpoint_id;
+ quiche::QuicheStringPiece endpoint_id;
if (perspective_ == Perspective::IS_CLIENT &&
reset->GetStringPiece(kEPID, &endpoint_id)) {
packet.endpoint_id = std::string(endpoint_id);
@@ -3324,8 +3332,8 @@
return false;
}
- // TODO(ianswett): Don't use QuicStringPiece as an intermediary.
- QuicStringPiece data;
+ // TODO(ianswett): Don't use quiche::QuicheStringPiece as an intermediary.
+ quiche::QuicheStringPiece data;
if (has_data_length) {
if (!reader->ReadStringPiece16(&data)) {
set_detailed_error("Unable to read frame data.");
@@ -3387,8 +3395,8 @@
frame->fin = false;
}
- // TODO(ianswett): Don't use QuicStringPiece as an intermediary.
- QuicStringPiece data;
+ // TODO(ianswett): Don't use quiche::QuicheStringPiece as an intermediary.
+ quiche::QuicheStringPiece data;
if (!reader->ReadStringPiece(&data, frame->data_length)) {
set_detailed_error("Unable to read frame data.");
return false;
@@ -3413,8 +3421,8 @@
}
frame->data_length = len;
- // TODO(ianswett): Don't use QuicStringPiece as an intermediary.
- QuicStringPiece data;
+ // TODO(ianswett): Don't use quiche::QuicheStringPiece as an intermediary.
+ quiche::QuicheStringPiece data;
if (!reader->ReadStringPiece(&data, frame->data_length)) {
set_detailed_error("Unable to read frame data.");
return false;
@@ -3492,10 +3500,11 @@
first_ack_block_underflow = true;
}
if (first_ack_block_underflow) {
- set_detailed_error(QuicStrCat("Underflow with first ack block length ",
- first_block_length, " largest acked is ",
- largest_acked, ".")
- .c_str());
+ set_detailed_error(
+ quiche::QuicheStrCat("Underflow with first ack block length ",
+ first_block_length, " largest acked is ",
+ largest_acked, ".")
+ .c_str());
return false;
}
@@ -3528,8 +3537,9 @@
}
if (ack_block_underflow) {
set_detailed_error(
- QuicStrCat("Underflow with ack block length ", current_block_length,
- ", end of block is ", first_received - gap, ".")
+ quiche::QuicheStrCat("Underflow with ack block length ",
+ current_block_length, ", end of block is ",
+ first_received - gap, ".")
.c_str());
return false;
}
@@ -3577,10 +3587,11 @@
}
if (largest_acked.ToUint64() <= delta_from_largest_observed) {
- set_detailed_error(QuicStrCat("delta_from_largest_observed too high: ",
- delta_from_largest_observed,
- ", largest_acked: ", largest_acked.ToUint64())
- .c_str());
+ set_detailed_error(
+ quiche::QuicheStrCat("delta_from_largest_observed too high: ",
+ delta_from_largest_observed,
+ ", largest_acked: ", largest_acked.ToUint64())
+ .c_str());
return false;
}
@@ -3605,9 +3616,9 @@
}
if (largest_acked.ToUint64() <= delta_from_largest_observed) {
set_detailed_error(
- QuicStrCat("delta_from_largest_observed too high: ",
- delta_from_largest_observed,
- ", largest_acked: ", largest_acked.ToUint64())
+ quiche::QuicheStrCat("delta_from_largest_observed too high: ",
+ delta_from_largest_observed,
+ ", largest_acked: ", largest_acked.ToUint64())
.c_str());
return false;
}
@@ -3713,10 +3724,11 @@
// error if the value is wrong.
if (ack_block_value + first_sending_packet_number_.ToUint64() >
largest_acked) {
- set_detailed_error(QuicStrCat("Underflow with first ack block length ",
- ack_block_value + 1, " largest acked is ",
- largest_acked, ".")
- .c_str());
+ set_detailed_error(
+ quiche::QuicheStrCat("Underflow with first ack block length ",
+ ack_block_value + 1, " largest acked is ",
+ largest_acked, ".")
+ .c_str());
return false;
}
@@ -3746,8 +3758,9 @@
// The test is written this way to detect wrap-arounds.
if ((gap_block_value + 2) > block_low) {
set_detailed_error(
- QuicStrCat("Underflow with gap block length ", gap_block_value + 1,
- " previous ack block start is ", block_low, ".")
+ quiche::QuicheStrCat("Underflow with gap block length ",
+ gap_block_value + 1,
+ " previous ack block start is ", block_low, ".")
.c_str());
return false;
}
@@ -3767,8 +3780,9 @@
if (ack_block_value + first_sending_packet_number_.ToUint64() >
(block_high - 1)) {
set_detailed_error(
- QuicStrCat("Underflow with ack block length ", ack_block_value + 1,
- " latest ack block end is ", block_high - 1, ".")
+ quiche::QuicheStrCat("Underflow with ack block length ",
+ ack_block_value + 1, " latest ack block end is ",
+ block_high - 1, ".")
.c_str());
return false;
}
@@ -3859,7 +3873,7 @@
// available in extracted_error_code.
frame->extracted_error_code = frame->quic_error_code;
- QuicStringPiece error_details;
+ quiche::QuicheStringPiece error_details;
if (!reader->ReadStringPiece16(&error_details)) {
set_detailed_error("Unable to read connection close error details.");
return false;
@@ -3890,7 +3904,7 @@
}
frame->last_good_stream_id = static_cast<QuicStreamId>(stream_id);
- QuicStringPiece reason_phrase;
+ quiche::QuicheStringPiece reason_phrase;
if (!reader->ReadStringPiece16(&reason_phrase)) {
set_detailed_error("Unable to read goaway reason.");
return false;
@@ -3944,7 +3958,7 @@
bool no_message_length,
QuicMessageFrame* frame) {
if (no_message_length) {
- QuicStringPiece remaining(reader->ReadRemainingPayload());
+ quiche::QuicheStringPiece remaining(reader->ReadRemainingPayload());
frame->data = remaining.data();
frame->message_length = remaining.length();
return true;
@@ -3956,7 +3970,7 @@
return false;
}
- QuicStringPiece message_piece;
+ quiche::QuicheStringPiece message_piece;
if (!reader->ReadStringPiece(&message_piece, message_length)) {
set_detailed_error("Unable to read message data");
return false;
@@ -3969,7 +3983,7 @@
}
// static
-QuicStringPiece QuicFramer::GetAssociatedDataFromEncryptedPacket(
+quiche::QuicheStringPiece QuicFramer::GetAssociatedDataFromEncryptedPacket(
QuicTransportVersion version,
const QuicEncryptedPacket& encrypted,
QuicConnectionIdLength destination_connection_id_length,
@@ -3981,7 +3995,7 @@
uint64_t retry_token_length,
QuicVariableLengthIntegerLength length_length) {
// TODO(ianswett): This is identical to QuicData::AssociatedData.
- return QuicStringPiece(
+ return quiche::QuicheStringPiece(
encrypted.data(),
GetStartOfEncryptedData(version, destination_connection_id_length,
source_connection_id_length, includes_version,
@@ -4086,9 +4100,10 @@
size_t output_length = 0;
if (!encrypter_[level]->EncryptPacket(
packet_number.ToUint64(),
- QuicStringPiece(buffer, ad_len), // Associated data
- QuicStringPiece(buffer + ad_len, total_len - ad_len), // Plaintext
- buffer + ad_len, // Destination buffer
+ quiche::QuicheStringPiece(buffer, ad_len), // Associated data
+ quiche::QuicheStringPiece(buffer + ad_len,
+ total_len - ad_len), // Plaintext
+ buffer + ad_len, // Destination buffer
&output_length, buffer_len - ad_len)) {
RaiseError(QUIC_ENCRYPTION_FAILURE);
return 0;
@@ -4127,7 +4142,7 @@
// Sample the ciphertext and generate the mask to use for header protection.
size_t sample_offset = pn_offset + 4;
QuicDataReader sample_reader(buffer, buffer_len);
- QuicStringPiece sample;
+ quiche::QuicheStringPiece sample;
if (!sample_reader.Seek(sample_offset) ||
!sample_reader.ReadStringPiece(&sample, kHPSampleLen)) {
QUIC_BUG << "Not enough bytes to sample: sample_offset " << sample_offset
@@ -4214,11 +4229,11 @@
// Read a sample from the ciphertext and compute the mask to use for header
// protection.
- QuicStringPiece remaining_packet = reader->PeekRemainingPayload();
+ quiche::QuicheStringPiece remaining_packet = reader->PeekRemainingPayload();
QuicDataReader sample_reader(remaining_packet);
// The sample starts 4 bytes after the start of the packet number.
- QuicStringPiece pn;
+ quiche::QuicheStringPiece pn;
if (!sample_reader.ReadStringPiece(&pn, 4)) {
QUIC_DVLOG(1) << "Not enough data to sample";
return false;
@@ -4286,7 +4301,7 @@
}
// Get the associated data, and apply the same unmasking operations to it.
- QuicStringPiece ad = GetAssociatedDataFromEncryptedPacket(
+ quiche::QuicheStringPiece ad = GetAssociatedDataFromEncryptedPacket(
version_.transport_version, packet,
GetIncludedDestinationConnectionIdLength(*header),
GetIncludedSourceConnectionIdLength(*header), header->version_flag,
@@ -4328,7 +4343,7 @@
return 0;
}
- QuicStringPiece associated_data =
+ quiche::QuicheStringPiece associated_data =
packet.AssociatedData(version_.transport_version);
// Copy in the header, because the encrypter only populates the encrypted
// plaintext content.
@@ -4375,8 +4390,8 @@
return min_plaintext_size;
}
-bool QuicFramer::DecryptPayload(QuicStringPiece encrypted,
- QuicStringPiece associated_data,
+bool QuicFramer::DecryptPayload(quiche::QuicheStringPiece encrypted,
+ quiche::QuicheStringPiece associated_data,
const QuicPacketHeader& header,
char* decrypted_buffer,
size_t buffer_length,
@@ -4946,8 +4961,8 @@
return false;
}
- // TODO(ianswett): Don't use QuicStringPiece as an intermediary.
- QuicStringPiece data;
+ // TODO(ianswett): Don't use quiche::QuicheStringPiece as an intermediary.
+ quiche::QuicheStringPiece data;
if (!reader->ReadStringPiece(&data, length)) {
set_detailed_error("Unable to read new token data.");
return false;
@@ -5664,7 +5679,7 @@
return false;
}
- QuicStringPiece phrase;
+ quiche::QuicheStringPiece phrase;
if (!reader->ReadStringPiece(&phrase, static_cast<size_t>(phrase_length))) {
set_detailed_error("Unable to read connection close error details.");
return false;
@@ -6118,7 +6133,7 @@
QuicConnectionId* destination_connection_id,
QuicConnectionId* source_connection_id,
bool* retry_token_present,
- QuicStringPiece* retry_token,
+ quiche::QuicheStringPiece* retry_token,
std::string* detailed_error) {
QuicDataReader reader(packet.data(), packet.length());
if (reader.IsDoneReading()) {
@@ -6288,7 +6303,7 @@
QuicConnectionId* source_connection_id,
QuicLongHeaderType* long_packet_type,
QuicVariableLengthIntegerLength* retry_token_length_length,
- QuicStringPiece* retry_token,
+ quiche::QuicheStringPiece* retry_token,
std::string* detailed_error) {
*version_present = false;
*has_length_prefix = false;
@@ -6297,7 +6312,7 @@
*source_connection_id = EmptyQuicConnectionId();
*long_packet_type = INVALID_PACKET_TYPE;
*retry_token_length_length = VARIABLE_LENGTH_INTEGER_LENGTH_0;
- *retry_token = QuicStringPiece();
+ *retry_token = quiche::QuicheStringPiece();
*detailed_error = "";
if (!reader->ReadUInt8(first_byte)) {
@@ -6565,11 +6580,11 @@
// the string is not found, or is not properly formed, it returns
// ErrorCode::QUIC_IETF_GQUIC_ERROR_MISSING
void MaybeExtractQuicErrorCode(QuicConnectionCloseFrame* frame) {
- std::vector<QuicStringPiece> ed =
- QuicTextUtils::Split(frame->error_details, ':');
+ std::vector<quiche::QuicheStringPiece> ed =
+ quiche::QuicheTextUtils::Split(frame->error_details, ':');
uint64_t extracted_error_code;
- if (ed.size() < 2 || !QuicTextUtils::IsAllDigits(ed[0]) ||
- !QuicTextUtils::StringToUint64(ed[0], &extracted_error_code)) {
+ if (ed.size() < 2 || !quiche::QuicheTextUtils::IsAllDigits(ed[0]) ||
+ !quiche::QuicheTextUtils::StringToUint64(ed[0], &extracted_error_code)) {
if (frame->close_type == IETF_QUIC_TRANSPORT_CONNECTION_CLOSE &&
frame->transport_error_code == NO_IETF_QUIC_ERROR) {
frame->extracted_error_code = QUIC_NO_ERROR;
@@ -6583,7 +6598,7 @@
// including, the split character, so the length of ed[0] is just the number
// of digits in the error number. In removing the prefix, 1 is added to the
// length to account for the :
- QuicStringPiece x = QuicStringPiece(frame->error_details);
+ quiche::QuicheStringPiece x = quiche::QuicheStringPiece(frame->error_details);
x.remove_prefix(ed[0].length() + 1);
frame->error_details = std::string(x);
frame->extracted_error_code =