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

Unified Diff: device/u2f/u2f_message.cc

Issue 2771673002: Use vectors instead of IOBuffer for U2fPackets (Closed)
Patch Set: Use vectors instead of IOBuffer for U2fPackets Created 3 years, 9 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 | « no previous file | device/u2f/u2f_message_unittest.cc » ('j') | device/u2f/u2f_packet.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/u2f/u2f_message.cc
diff --git a/device/u2f/u2f_message.cc b/device/u2f/u2f_message.cc
index 8cf2281ef24504e9ab54280a9c78550b066a0ca1..8259147ba761d53fc97e5d8d56d313e390b7a7ad 100644
--- a/device/u2f/u2f_message.cc
+++ b/device/u2f/u2f_message.cc
@@ -30,8 +30,9 @@ std::unique_ptr<U2fMessage> U2fMessage::CreateFromSerializedData(
static_cast<size_t>(buf->size()) < kInitPacketHeader)
return nullptr;
+ std::vector<uint8_t> init_data(buf->data(), buf->data() + buf->size());
Reilly Grant (use Gerrit) 2017/03/22 23:08:16 This method should take a const std::vector<uint8_
Casey Piper 2017/03/23 03:47:24 Done.
std::unique_ptr<U2fInitPacket> init_packet =
- U2fInitPacket::CreateFromSerializedData(buf, &remaining_size);
+ U2fInitPacket::CreateFromSerializedData(init_data, &remaining_size);
if (init_packet == nullptr)
return nullptr;
@@ -95,10 +96,12 @@ std::list<std::unique_ptr<U2fPacket>>::const_iterator U2fMessage::end() {
scoped_refptr<net::IOBufferWithSize> U2fMessage::PopNextPacket() {
if (NumPackets() > 0) {
- scoped_refptr<net::IOBufferWithSize> buf =
- packets_.front()->GetSerializedBuffer();
+ std::vector<uint8_t> data = packets_.front()->GetSerializedData();
Reilly Grant (use Gerrit) 2017/03/22 23:08:17 If GetSerializedData() will be building this vecto
Casey Piper 2017/03/23 03:47:24 Done.
+ auto buffer = make_scoped_refptr(new net::IOBufferWithSize(data.size()));
+ memcpy(buffer->data(), data.data(), data.size());
+
packets_.pop_front();
- return buf;
+ return buffer;
}
return nullptr;
}
@@ -106,8 +109,10 @@ scoped_refptr<net::IOBufferWithSize> U2fMessage::PopNextPacket() {
bool U2fMessage::AddContinuationPacket(
scoped_refptr<net::IOBufferWithSize> buf) {
size_t remaining_size = remaining_size_;
+ std::vector<uint8_t> cont_data(buf->data(), buf->data() + buf->size());
std::unique_ptr<U2fContinuationPacket> cont_packet =
- U2fContinuationPacket::CreateFromSerializedData(buf, &remaining_size);
+ U2fContinuationPacket::CreateFromSerializedData(cont_data,
+ &remaining_size);
// Reject packets with a different channel id
if (cont_packet == nullptr || channel_id_ != cont_packet->channel_id())
« no previous file with comments | « no previous file | device/u2f/u2f_message_unittest.cc » ('j') | device/u2f/u2f_packet.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698