Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
| 6 #include "device/u2f/u2f_packet.h" | 6 #include "device/u2f/u2f_packet.h" |
| 7 #include "net/base/io_buffer.h" | 7 #include "net/base/io_buffer.h" |
| 8 | 8 |
| 9 #include "u2f_message.h" | 9 #include "u2f_message.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 std::unique_ptr<U2fMessage> U2fMessage::CreateFromSerializedData( | 25 std::unique_ptr<U2fMessage> U2fMessage::CreateFromSerializedData( |
| 26 scoped_refptr<net::IOBufferWithSize> buf) { | 26 scoped_refptr<net::IOBufferWithSize> buf) { |
| 27 size_t remaining_size = 0; | 27 size_t remaining_size = 0; |
| 28 if (buf == nullptr || | 28 if (buf == nullptr || |
| 29 static_cast<size_t>(buf->size()) > U2fPacket::kPacketSize || | 29 static_cast<size_t>(buf->size()) > U2fPacket::kPacketSize || |
| 30 static_cast<size_t>(buf->size()) < kInitPacketHeader) | 30 static_cast<size_t>(buf->size()) < kInitPacketHeader) |
| 31 return nullptr; | 31 return nullptr; |
| 32 | 32 |
| 33 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.
| |
| 33 std::unique_ptr<U2fInitPacket> init_packet = | 34 std::unique_ptr<U2fInitPacket> init_packet = |
| 34 U2fInitPacket::CreateFromSerializedData(buf, &remaining_size); | 35 U2fInitPacket::CreateFromSerializedData(init_data, &remaining_size); |
| 35 if (init_packet == nullptr) | 36 if (init_packet == nullptr) |
| 36 return nullptr; | 37 return nullptr; |
| 37 | 38 |
| 38 return base::MakeUnique<U2fMessage>(std::move(init_packet), remaining_size); | 39 return base::MakeUnique<U2fMessage>(std::move(init_packet), remaining_size); |
| 39 } | 40 } |
| 40 | 41 |
| 41 U2fMessage::U2fMessage(std::unique_ptr<U2fInitPacket> init_packet, | 42 U2fMessage::U2fMessage(std::unique_ptr<U2fInitPacket> init_packet, |
| 42 size_t remaining_size) | 43 size_t remaining_size) |
| 43 : remaining_size_(remaining_size) { | 44 : remaining_size_(remaining_size) { |
| 44 channel_id_ = init_packet->channel_id(); | 45 channel_id_ = init_packet->channel_id(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 std::list<std::unique_ptr<U2fPacket>>::const_iterator U2fMessage::begin() { | 89 std::list<std::unique_ptr<U2fPacket>>::const_iterator U2fMessage::begin() { |
| 89 return packets_.cbegin(); | 90 return packets_.cbegin(); |
| 90 } | 91 } |
| 91 | 92 |
| 92 std::list<std::unique_ptr<U2fPacket>>::const_iterator U2fMessage::end() { | 93 std::list<std::unique_ptr<U2fPacket>>::const_iterator U2fMessage::end() { |
| 93 return packets_.cend(); | 94 return packets_.cend(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 scoped_refptr<net::IOBufferWithSize> U2fMessage::PopNextPacket() { | 97 scoped_refptr<net::IOBufferWithSize> U2fMessage::PopNextPacket() { |
| 97 if (NumPackets() > 0) { | 98 if (NumPackets() > 0) { |
| 98 scoped_refptr<net::IOBufferWithSize> buf = | 99 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.
| |
| 99 packets_.front()->GetSerializedBuffer(); | 100 auto buffer = make_scoped_refptr(new net::IOBufferWithSize(data.size())); |
| 101 memcpy(buffer->data(), data.data(), data.size()); | |
| 102 | |
| 100 packets_.pop_front(); | 103 packets_.pop_front(); |
| 101 return buf; | 104 return buffer; |
| 102 } | 105 } |
| 103 return nullptr; | 106 return nullptr; |
| 104 } | 107 } |
| 105 | 108 |
| 106 bool U2fMessage::AddContinuationPacket( | 109 bool U2fMessage::AddContinuationPacket( |
| 107 scoped_refptr<net::IOBufferWithSize> buf) { | 110 scoped_refptr<net::IOBufferWithSize> buf) { |
| 108 size_t remaining_size = remaining_size_; | 111 size_t remaining_size = remaining_size_; |
| 112 std::vector<uint8_t> cont_data(buf->data(), buf->data() + buf->size()); | |
| 109 std::unique_ptr<U2fContinuationPacket> cont_packet = | 113 std::unique_ptr<U2fContinuationPacket> cont_packet = |
| 110 U2fContinuationPacket::CreateFromSerializedData(buf, &remaining_size); | 114 U2fContinuationPacket::CreateFromSerializedData(cont_data, |
| 115 &remaining_size); | |
| 111 | 116 |
| 112 // Reject packets with a different channel id | 117 // Reject packets with a different channel id |
| 113 if (cont_packet == nullptr || channel_id_ != cont_packet->channel_id()) | 118 if (cont_packet == nullptr || channel_id_ != cont_packet->channel_id()) |
| 114 return false; | 119 return false; |
| 115 | 120 |
| 116 remaining_size_ = remaining_size; | 121 remaining_size_ = remaining_size; |
| 117 packets_.push_back(std::move(cont_packet)); | 122 packets_.push_back(std::move(cont_packet)); |
| 118 return true; | 123 return true; |
| 119 } | 124 } |
| 120 | 125 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 131 } | 136 } |
| 132 | 137 |
| 133 return data; | 138 return data; |
| 134 } | 139 } |
| 135 | 140 |
| 136 size_t U2fMessage::NumPackets() { | 141 size_t U2fMessage::NumPackets() { |
| 137 return packets_.size(); | 142 return packets_.size(); |
| 138 } | 143 } |
| 139 | 144 |
| 140 } // namespace device | 145 } // namespace device |
| OLD | NEW |