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

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

Issue 2502103002: Add FIDO U2F message and packet classes (Closed)
Patch Set: Add FIDO U2F message and packet classes Created 4 years, 1 month 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
« device/u2f/u2f_message.cc ('K') | « device/u2f/u2f_packet.h ('k') | no next file » | 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 <iostream>
6 #include "device/u2f/u2f_packet.h"
7
8 namespace device {
9
10 U2fPacket::U2fPacket(const std::vector<char> data,
11 const char channel_id[kChannelIdSize])
12 : data_(data) {
13 for (size_t index = 0; index < kChannelIdSize; ++index) {
14 channel_id_[index] = channel_id[index];
15 }
Reilly Grant (use Gerrit) 2016/11/23 22:21:51 nit: unnecessary braces
Casey Piper 2016/11/29 22:11:15 Done.
16 }
17
18 U2fPacket::~U2fPacket() {}
19
20 scoped_refptr<net::IOBufferWithSize> U2fPacket::GetBuffer() {
21 if (serialized_) {
22 return serialized_;
23 } else {
24 scoped_refptr<net::IOBufferWithSize> buffer(new net::IOBufferWithSize(0));
25 return buffer;
Reilly Grant (use Gerrit) 2016/11/23 22:21:51 one line: return make_scoped_refptr(new net::IOBuf
Casey Piper 2016/11/29 22:11:15 Done.
26 }
27 }
28
29 // U2F Initialization packet is defined as:
30 // Offset Length
31 // 0 4 Channel ID
32 // 4 1 Command ID
33 // 5 1 High order packet payload size
34 // 6 1 Low order packet payload size
35 // 7 (s-7) Payload data
36 U2fInitPacket::U2fInitPacket(const char channel_id[kChannelIdSize],
37 const char cmd,
38 const std::vector<char> data)
39 : U2fPacket(data, channel_id), command_(cmd) {
40 serialized_ = new net::IOBufferWithSize(kPacketSize);
41 size_t index = 0;
42 uint16_t size = data.size();
43 serialized_->data()[index++] = 0;
44 for (size_t i = 0; i < kChannelIdSize; ++i, index++) {
45 serialized_->data()[index] = channel_id_[i];
46 }
Reilly Grant (use Gerrit) 2016/11/23 22:21:51 nit (here and below): no braces for single line if
Casey Piper 2016/11/29 22:11:15 Acknowledged.
47
48 serialized_->data()[index++] = command_;
49 serialized_->data()[index++] = (size >> 8) & 0xff;
50 serialized_->data()[index++] = size & 0xff;
51 for (size_t data_idx = 0; data_idx < data_.size(); ++data_idx) {
52 serialized_->data()[index++] = data_.at(data_idx);
53 }
54 while ((int)index < serialized_->size()) {
55 serialized_->data()[index++] = 0;
56 }
57 }
58
59 U2fInitPacket::~U2fInitPacket() {}
60
61 // U2F Continuation packet is defined as:
62 // Offset Length
63 // 0 4 Channel ID
64 // 4 1 Packet sequence 0x00..0x7f
65 // 5 (s-5) Payload data
66 U2fContPacket::U2fContPacket(const char channel_id[kChannelIdSize],
67 const char sequence,
68 std::vector<char> data)
69 : U2fPacket(data, channel_id), sequence_(sequence) {
70 serialized_ = new net::IOBufferWithSize(kPacketSize);
71 size_t index = 0;
72 for (; index < kChannelIdSize; ++index) {
73 serialized_->data()[index] = channel_id_[index];
74 }
75
76 serialized_->data()[index++] = sequence_;
77 for (size_t data_idx = 0; data_idx < data_.size(); ++data_idx) {
78 serialized_->data()[index++] = data_.at(data_idx);
79 }
80 }
81
82 U2fContPacket::~U2fContPacket() {}
83 } // namespace device;
Reilly Grant (use Gerrit) 2016/11/23 22:21:51 no ;
Casey Piper 2016/11/29 22:11:15 Done.
OLDNEW
« device/u2f/u2f_message.cc ('K') | « device/u2f/u2f_packet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698