Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1138)

Unified Diff: net/quic/quic_framer.cc

Issue 912163002: Change the QuicEncrypter to accept a pre-allocated buffer instead of (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Change_QuicPacketCreator_85897935
Patch Set: Reverting logging changes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/quic_connection_test.cc ('k') | net/quic/quic_framer_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_framer.cc
diff --git a/net/quic/quic_framer.cc b/net/quic/quic_framer.cc
index 364bdaca767a11eac21e024bf021aaf2ec131ad4..3eda6b3f847f293e8c4d50e732a5c767644ec392 100644
--- a/net/quic/quic_framer.cc
+++ b/net/quic/quic_framer.cc
@@ -1625,19 +1625,27 @@ QuicEncryptedPacket* QuicFramer::EncryptPacket(
const QuicPacket& packet) {
DCHECK(encrypter_[level].get() != nullptr);
- scoped_ptr<QuicData> out(encrypter_[level]->EncryptPacket(
- packet_sequence_number, packet.AssociatedData(), packet.Plaintext()));
- if (out.get() == nullptr) {
- RaiseError(QUIC_ENCRYPTION_FAILURE);
- return nullptr;
- }
+ // Allocate a large enough buffer for the header and the encrypted data.
+ const size_t encrypted_len =
+ encrypter_[level]->GetCiphertextSize(packet.Plaintext().length());
StringPiece header_data = packet.BeforePlaintext();
- size_t len = header_data.length() + out->length();
+ const size_t len = header_data.length() + encrypted_len;
+ // TODO(ianswett): Consider allocating this on the stack in the typical case.
char* buffer = new char[len];
- // TODO(rch): eliminate this buffer copy by passing in a buffer to Encrypt().
+ // Copy in the header, because the encrypter only populates the encrypted
+ // plaintext content.
memcpy(buffer, header_data.data(), header_data.length());
- memcpy(buffer + header_data.length(), out->data(), out->length());
- return new QuicEncryptedPacket(buffer, len, true);
+ // Encrypt the plaintext into the buffer.
+ size_t output_length = 0;
+ if (!encrypter_[level]->EncryptPacket(
+ packet_sequence_number, packet.AssociatedData(), packet.Plaintext(),
+ buffer + header_data.length(), &output_length, encrypted_len)) {
+ RaiseError(QUIC_ENCRYPTION_FAILURE);
+ return nullptr;
+ }
+
+ return new QuicEncryptedPacket(buffer, header_data.length() + output_length,
+ true);
}
size_t QuicFramer::GetMaxPlaintextSize(size_t ciphertext_size) {
« no previous file with comments | « net/quic/quic_connection_test.cc ('k') | net/quic/quic_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698