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

Unified Diff: device/u2f/u2f_message.h

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
Index: device/u2f/u2f_message.h
diff --git a/device/u2f/u2f_message.h b/device/u2f/u2f_message.h
new file mode 100644
index 0000000000000000000000000000000000000000..5642c002813b074d0351fe7ea0ca9a0746864b29
--- /dev/null
+++ b/device/u2f/u2f_message.h
@@ -0,0 +1,65 @@
+// 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.
+
+#ifndef DEVICE_U2F_U2F_MESSAGE_H_
+#define DEVICE_U2F_U2F_MESSAGE_H_
+
+#include <list>
+#include <vector>
+#include "base/macros.h"
+#include "device/u2f/u2f_packet.h"
+
+namespace device {
+
+class U2fMessage : public base::RefCountedThreadSafe<U2fMessage> {
+ public:
+ enum class Type : uint8_t {
juanlang (chromium.org) 2016/11/30 19:41:32 It'd be helpful to reference the U2F specs somewhe
+ CMD_PING = 0x81,
+ CMD_ATR = 0x82,
juanlang (chromium.org) 2016/11/30 19:41:32 This is not part of the U2F HID standard, please r
Casey Piper 2016/11/30 22:05:46 Done.
+ CMD_APDU = 0x83,
juanlang (chromium.org) 2016/11/30 19:41:32 In the U2F HID standard, this is known as MSG rath
Casey Piper 2016/11/30 22:05:46 Done.
+ CMD_LOCK = 0x84,
juanlang (chromium.org) 2016/11/30 19:41:32 This is not part of the U2F HID standard, please r
Casey Piper 2016/11/30 22:05:46 Done.
+ CMD_SYSINFO = 0x85,
juanlang (chromium.org) 2016/11/30 19:41:32 Ditto.
Casey Piper 2016/11/30 22:05:46 Acknowledged.
+ CMD_INIT = 0x86,
+ CMD_PROMPT = 0x87,
juanlang (chromium.org) 2016/11/30 19:41:32 Ditto.
Casey Piper 2016/11/30 22:05:46 Acknowledged.
+ CMD_WINK = 0x88,
+ CMD_BLE_UID = 0xb5,
juanlang (chromium.org) 2016/11/30 19:41:32 Ditto.
Casey Piper 2016/11/30 22:05:46 Acknowledged.
+ CMD_USB_TEST = 0xb9,
juanlang (chromium.org) 2016/11/30 19:41:32 Ditto.
Casey Piper 2016/11/30 22:05:46 Acknowledged.
+ CMD_DFU = 0xba,
juanlang (chromium.org) 2016/11/30 19:41:32 Ditto.
Casey Piper 2016/11/30 22:05:46 Acknowledged.
+ CMD_SYNC = 0xbc,
juanlang (chromium.org) 2016/11/30 19:41:32 No action required, just an FYI: This is not part
Casey Piper 2016/11/30 22:05:46 Acknowledged.
+ CMD_ERROR = 0xbf,
+ };
+
+ static const size_t kInitPacketHeader = 7;
+ static const size_t kContPacketHeader = 5;
+ static const size_t kInitPacketDataSize = 57;
juanlang (chromium.org) 2016/11/30 19:41:32 Funny that such a small line will generate this vo
Casey Piper 2016/11/30 22:05:46 Done.
+ static const size_t kContPacketDataSize = 59;
+
+ // Messages are limited to an init packet and 128 cont packets
+ // Maximum payload length therefore is 64-7 + 128 * (64-5) = 7609 bytes
+ static const size_t kMaxMessageSize = 7609;
+
+ static scoped_refptr<U2fMessage> Create(
+ const uint8_t channel_id[U2fPacket::kChannelIdSize],
+ const Type type,
+ const std::vector<uint8_t>& data);
+
+ scoped_refptr<net::IOBufferWithSize> GetNextPacket();
+ size_t NumPackets();
+
+ std::list<scoped_refptr<U2fPacket>>::const_iterator begin();
+ std::list<scoped_refptr<U2fPacket>>::const_iterator end();
+
+ private:
+ friend class base::RefCountedThreadSafe<U2fMessage>;
+ std::list<scoped_refptr<U2fPacket>> packets_;
+ U2fMessage(const uint8_t channel_id[U2fPacket::kChannelIdSize],
+ const Type type,
+ const std::vector<uint8_t>& data);
Reilly Grant (use Gerrit) 2016/11/30 20:53:46 Keep these definitions in order with blank lines b
Casey Piper 2016/11/30 22:05:46 Acknowledged.
+
+ protected:
+ virtual ~U2fMessage();
Reilly Grant (use Gerrit) 2016/11/30 20:53:46 Protected before private.
Casey Piper 2016/11/30 22:05:46 Acknowledged.
+};
+} // namespace device
+
+#endif // DEVICE_U2F_U2F_MESSAGE_H_
« no previous file with comments | « device/u2f/DEPS ('k') | device/u2f/u2f_message.cc » ('j') | device/u2f/u2f_message_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698