Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "device/u2f/u2f_message.h" | |
| 6 #include "device/u2f/u2f_packet.h" | |
| 7 | |
| 8 namespace device { | |
| 9 | |
| 10 U2fMessage::U2fMessage(const char channel_id[U2fPacket::kChannelIdSize], | |
| 11 const u2f_message_type type, | |
| 12 const std::vector<char> data) { | |
| 13 size_t size = data.size(); | |
|
Reilly Grant (use Gerrit)
2016/11/23 22:21:50
Name this remaining_size. I was confused why we we
Casey Piper
2016/11/29 22:11:15
Done.
| |
| 14 char sequence = 0; | |
| 15 | |
| 16 if (size > kMaxMessageSize) | |
| 17 return; | |
|
Reilly Grant (use Gerrit)
2016/11/23 22:21:50
If you're doing validation in the constructor I wo
| |
| 18 | |
| 19 std::vector<char> payload; | |
| 20 std::vector<char>::const_iterator first = data.begin(); | |
| 21 std::vector<char>::const_iterator last; | |
| 22 | |
| 23 if (size > kInitPacketDataSize) { | |
| 24 last = data.begin() + kInitPacketDataSize; | |
| 25 size -= kInitPacketDataSize; | |
| 26 } else { | |
| 27 last = data.begin() + size; | |
| 28 size = 0; | |
| 29 } | |
| 30 | |
| 31 payload.insert(std::end(payload), first, last); | |
| 32 | |
| 33 packets_.push_back(scoped_refptr<U2fPacket>( | |
| 34 static_cast<U2fPacket*>(new U2fInitPacket(channel_id, type, payload)))); | |
|
Reilly Grant (use Gerrit)
2016/11/23 22:21:50
A static cast is unnecessary here.
Casey Piper
2016/11/29 22:11:15
Acknowledged.
| |
| 35 | |
| 36 while (size > 0) { | |
| 37 first = last; | |
| 38 if (size > kContPacketDataSize) { | |
| 39 last = first + kContPacketDataSize; | |
| 40 size -= kContPacketDataSize; | |
| 41 } else { | |
| 42 last = first + size; | |
| 43 size = 0; | |
| 44 } | |
| 45 payload.clear(); | |
| 46 payload.insert(std::end(payload), first, last); | |
|
Reilly Grant (use Gerrit)
2016/11/23 22:21:50
I found this reuse of payload confusing. You can j
Casey Piper
2016/11/29 22:11:15
Done.
| |
| 47 | |
| 48 packets_.push_back(scoped_refptr<U2fPacket>(static_cast<U2fPacket*>( | |
| 49 new U2fContPacket(channel_id, sequence, payload)))); | |
| 50 sequence++; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 U2fMessage::~U2fMessage() {} | |
| 55 | |
| 56 scoped_refptr<net::IOBufferWithSize> U2fMessage::GetNextPacket() { | |
| 57 if (NumPackets() > 0) { | |
| 58 scoped_refptr<net::IOBufferWithSize> buf = packets_.front()->GetBuffer(); | |
| 59 packets_.pop_front(); | |
| 60 return buf; | |
| 61 } | |
| 62 return 0; | |
|
Reilly Grant (use Gerrit)
2016/11/23 22:21:50
s/0/nullptr/
Casey Piper
2016/11/29 22:11:15
Done.
| |
| 63 } | |
| 64 | |
| 65 size_t U2fMessage::NumPackets() { | |
| 66 return packets_.size(); | |
| 67 } | |
| 68 | |
| 69 } // namespace device | |
| OLD | NEW |