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

Unified 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 side-by-side diff with in-line comments
Download patch
« device/u2f/u2f_message.cc ('K') | « device/u2f/u2f_packet.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/u2f/u2f_packet.cc
diff --git a/device/u2f/u2f_packet.cc b/device/u2f/u2f_packet.cc
new file mode 100644
index 0000000000000000000000000000000000000000..17d471b49a7afc6807bfdb48d0f6d02ef6a9310c
--- /dev/null
+++ b/device/u2f/u2f_packet.cc
@@ -0,0 +1,83 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <iostream>
+#include "device/u2f/u2f_packet.h"
+
+namespace device {
+
+U2fPacket::U2fPacket(const std::vector<char> data,
+ const char channel_id[kChannelIdSize])
+ : data_(data) {
+ for (size_t index = 0; index < kChannelIdSize; ++index) {
+ channel_id_[index] = channel_id[index];
+ }
Reilly Grant (use Gerrit) 2016/11/23 22:21:51 nit: unnecessary braces
Casey Piper 2016/11/29 22:11:15 Done.
+}
+
+U2fPacket::~U2fPacket() {}
+
+scoped_refptr<net::IOBufferWithSize> U2fPacket::GetBuffer() {
+ if (serialized_) {
+ return serialized_;
+ } else {
+ scoped_refptr<net::IOBufferWithSize> buffer(new net::IOBufferWithSize(0));
+ 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.
+ }
+}
+
+// U2F Initialization packet is defined as:
+// Offset Length
+// 0 4 Channel ID
+// 4 1 Command ID
+// 5 1 High order packet payload size
+// 6 1 Low order packet payload size
+// 7 (s-7) Payload data
+U2fInitPacket::U2fInitPacket(const char channel_id[kChannelIdSize],
+ const char cmd,
+ const std::vector<char> data)
+ : U2fPacket(data, channel_id), command_(cmd) {
+ serialized_ = new net::IOBufferWithSize(kPacketSize);
+ size_t index = 0;
+ uint16_t size = data.size();
+ serialized_->data()[index++] = 0;
+ for (size_t i = 0; i < kChannelIdSize; ++i, index++) {
+ serialized_->data()[index] = channel_id_[i];
+ }
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.
+
+ serialized_->data()[index++] = command_;
+ serialized_->data()[index++] = (size >> 8) & 0xff;
+ serialized_->data()[index++] = size & 0xff;
+ for (size_t data_idx = 0; data_idx < data_.size(); ++data_idx) {
+ serialized_->data()[index++] = data_.at(data_idx);
+ }
+ while ((int)index < serialized_->size()) {
+ serialized_->data()[index++] = 0;
+ }
+}
+
+U2fInitPacket::~U2fInitPacket() {}
+
+// U2F Continuation packet is defined as:
+// Offset Length
+// 0 4 Channel ID
+// 4 1 Packet sequence 0x00..0x7f
+// 5 (s-5) Payload data
+U2fContPacket::U2fContPacket(const char channel_id[kChannelIdSize],
+ const char sequence,
+ std::vector<char> data)
+ : U2fPacket(data, channel_id), sequence_(sequence) {
+ serialized_ = new net::IOBufferWithSize(kPacketSize);
+ size_t index = 0;
+ for (; index < kChannelIdSize; ++index) {
+ serialized_->data()[index] = channel_id_[index];
+ }
+
+ serialized_->data()[index++] = sequence_;
+ for (size_t data_idx = 0; data_idx < data_.size(); ++data_idx) {
+ serialized_->data()[index++] = data_.at(data_idx);
+ }
+}
+
+U2fContPacket::~U2fContPacket() {}
+} // namespace device;
Reilly Grant (use Gerrit) 2016/11/23 22:21:51 no ;
Casey Piper 2016/11/29 22:11:15 Done.
« 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