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

Unified Diff: device/u2f/u2f_packet.h

Issue 2502103002: Add FIDO U2F message and packet classes (Closed)
Patch Set: Adding constructors and fix issues when creating messages and packets from IOBuffers 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 side-by-side diff with in-line comments
Download patch
Index: device/u2f/u2f_packet.h
diff --git a/device/u2f/u2f_packet.h b/device/u2f/u2f_packet.h
new file mode 100644
index 0000000000000000000000000000000000000000..7d42f5c32d06ef872ff420c29cd8c40c1fb707c0
--- /dev/null
+++ b/device/u2f/u2f_packet.h
@@ -0,0 +1,82 @@
+// 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_PACKET_H_
+#define DEVICE_U2F_U2F_PACKET_H_
+
+#include "base/macros.h"
+#include "net/base/io_buffer.h"
+
+namespace device {
+class U2fPacket : public base::RefCountedThreadSafe<U2fPacket> {
+ public:
+ U2fPacket(const std::vector<uint8_t> data, const uint8_t channel_id[]);
juanlang (chromium.org) 2016/12/07 18:29:26 Same comment about passing channel_id as a uint32_
Casey Piper 2016/12/09 00:15:54 Done.
+
+ scoped_refptr<net::IOBufferWithSize> GetBuffer();
juanlang (chromium.org) 2016/12/07 18:29:26 What's the difference between GetBuffer() and GetD
Casey Piper 2016/12/09 00:15:54 I'll change it and hopefully they'll be more clear
+ const std::vector<uint8_t> GetData();
+ uint8_t* GetChannelId();
+
+ static const size_t kChannelIdSize = 4;
juanlang (chromium.org) 2016/12/07 18:29:26 If you use uint32_t for the channel_id, I don't th
Casey Piper 2016/12/09 00:15:54 Done.
+ // Packet size of 64 bytes + 1 byte report ID
+ static const size_t kPacketSize = 65;
juanlang (chromium.org) 2016/12/07 18:29:26 Seems like an implementation detail that could be
Casey Piper 2016/12/09 00:15:54 Moved to protected.
+
+ protected:
+ U2fPacket();
+ virtual ~U2fPacket();
+
+ std::vector<uint8_t> data_;
+ uint8_t channel_id_[kChannelIdSize];
+ scoped_refptr<net::IOBufferWithSize> serialized_;
+
+ private:
+ friend class base::RefCountedThreadSafe<U2fPacket>;
+};
+
+class U2fInitPacket : public U2fPacket {
+ public:
+ U2fInitPacket(const uint8_t channel_id[kChannelIdSize],
+ const uint8_t cmd,
+ const std::vector<uint8_t> data,
+ const uint16_t payload_length);
+
+ static scoped_refptr<U2fInitPacket> Create(
+ scoped_refptr<net::IOBufferWithSize> buf,
+ size_t* remaining_size);
+ uint8_t GetCommand();
+ uint16_t GetPayloadLength();
+
+ protected:
+ ~U2fInitPacket() final;
+
+ private:
+ U2fInitPacket(scoped_refptr<net::IOBufferWithSize> buf,
+ size_t* remaining_size);
+
+ uint8_t command_;
+ uint16_t payload_length_;
+};
+
+class U2fContPacket : public U2fPacket {
+ public:
+ U2fContPacket(const uint8_t channel_id[kChannelIdSize],
+ const uint8_t sequence,
+ std::vector<uint8_t> data);
+ static scoped_refptr<U2fContPacket> Create(
+ scoped_refptr<net::IOBufferWithSize> buf,
+ size_t* remaining_size);
+
+ uint8_t GetSequence();
+
+ protected:
+ ~U2fContPacket() final;
+
+ private:
+ U2fContPacket(scoped_refptr<net::IOBufferWithSize> buf,
+ size_t* remaining_size);
+
+ uint8_t sequence_;
+};
+} // namespace device
+
+#endif // DEVICE_U2F_U2F_PACKET_H_

Powered by Google App Engine
This is Rietveld 408576698