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

Side by Side Diff: device/u2f/u2f_message.cc

Issue 2502103002: Add FIDO U2F message and packet classes (Closed)
Patch Set: Add FIDO U2F message and packet classes Created 4 years 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 unified diff | Download patch
« no previous file with comments | « device/u2f/u2f_message.h ('k') | device/u2f/u2f_message_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // static
11 scoped_refptr<U2fMessage> U2fMessage::Create(
12 const char channel_id[U2fPacket::kChannelIdSize],
Casey Piper 2016/11/29 22:17:56 Should I change all char's to uint8_t?
Reilly Grant (use Gerrit) 2016/11/29 22:51:48 Yes.
Casey Piper 2016/11/30 17:37:04 Done.
13 const Type type,
14 const std::vector<uint8_t>& data) {
15 if (data.size() > kMaxMessageSize)
16 return nullptr;
17
18 return make_scoped_refptr(new U2fMessage(channel_id, type, data));
19 }
20
21 U2fMessage::U2fMessage(const char channel_id[U2fPacket::kChannelIdSize],
22 const Type type,
23 const std::vector<uint8_t>& data) {
24 size_t remaining_size = data.size();
25 char sequence = 0;
26
27 std::vector<uint8_t>::const_iterator first = data.begin();
28 std::vector<uint8_t>::const_iterator last;
29
30 if (remaining_size > kInitPacketDataSize) {
31 last = data.begin() + kInitPacketDataSize;
32 remaining_size -= kInitPacketDataSize;
33 } else {
34 last = data.begin() + remaining_size;
35 remaining_size = 0;
36 }
37
38 packets_.push_back(scoped_refptr<U2fPacket>(
39 new U2fInitPacket(channel_id, static_cast<char>(type),
40 std::vector<uint8_t>(first, last), data.size())));
41
42 while (remaining_size > 0) {
43 first = last;
44 if (remaining_size > kContPacketDataSize) {
45 last = first + kContPacketDataSize;
46 remaining_size -= kContPacketDataSize;
47 } else {
48 last = first + remaining_size;
49 remaining_size = 0;
50 }
51
52 packets_.push_back(make_scoped_refptr(new U2fContPacket(
53 channel_id, sequence, std::vector<uint8_t>(first, last))));
54 sequence++;
55 }
56 }
57
58 U2fMessage::~U2fMessage() {}
59
60 std::list<scoped_refptr<U2fPacket>>::const_iterator U2fMessage::begin() {
61 return packets_.begin();
62 }
63
64 std::list<scoped_refptr<U2fPacket>>::const_iterator U2fMessage::end() {
65 return packets_.end();
66 }
67
68 scoped_refptr<net::IOBufferWithSize> U2fMessage::GetNextPacket() {
69 if (NumPackets() > 0) {
70 scoped_refptr<net::IOBufferWithSize> buf = packets_.front()->GetBuffer();
71 packets_.pop_front();
72 return buf;
73 }
74 return nullptr;
75 }
76
77 size_t U2fMessage::NumPackets() {
78 return packets_.size();
79 }
80
81 } // namespace device
OLDNEW
« no previous file with comments | « device/u2f/u2f_message.h ('k') | device/u2f/u2f_message_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698