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

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

Issue 2502103002: Add FIDO U2F message and packet classes (Closed)
Patch Set: Change channel id to uint32_t from uint8_t[4] and fix additional review comments 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
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 #ifndef DEVICE_U2F_U2F_MESSAGE_H_
6 #define DEVICE_U2F_U2F_MESSAGE_H_
7
8 #include <list>
9 #include <vector>
10 #include "base/gtest_prod_util.h"
11 #include "base/macros.h"
12 #include "device/u2f/u2f_packet.h"
13
14 namespace device {
15
16 // U2fMessages are defined by the specification at
17 // http://fidoalliance.org/specs/u2f-specs-1.0-bt-nfc-id-amendment/fido-u2f-hid- protocol.html
18 // A U2fMessage object represents a list of U2fPackets. Basic information
19 // about the message are available through class methods.
20 class U2fMessage : public base::RefCountedThreadSafe<U2fMessage> {
21 public:
22 enum class Type : uint8_t {
23 CMD_PING = 0x81,
24 CMD_MSG = 0x83,
25 CMD_INIT = 0x86,
26 CMD_WINK = 0x88,
27 CMD_ERROR = 0xbf,
28 };
29
30 static scoped_refptr<U2fMessage> Create(const uint32_t channel_id,
31 const Type type,
32 const std::vector<uint8_t>& data);
33 // Reconstruct a message from serialized message data
34 static scoped_refptr<U2fMessage> CreateFromSerializedData(
35 scoped_refptr<net::IOBufferWithSize> buf);
36 // Pop front of queue with next packet
37 scoped_refptr<net::IOBufferWithSize> PopNextPacket();
38 // Adds a continuation packet to the packet list, from the serialized
39 // response value
40 bool AddContinuationPacket(scoped_refptr<net::IOBufferWithSize> packet_buf);
41 size_t NumPackets();
42 // Returns entire message payload
43 const std::vector<uint8_t> GetMessagePayload();
Reilly Grant (use Gerrit) 2016/12/09 01:19:43 If the intent was to make this method const then t
Casey Piper 2016/12/09 18:56:50 Done.
44 uint32_t GetChannelId();
45 // Message construction complete
46 bool MessageComplete();
47 std::list<scoped_refptr<U2fPacket>>::const_iterator begin();
48 std::list<scoped_refptr<U2fPacket>>::const_iterator end();
49
50 protected:
51 virtual ~U2fMessage();
52
53 private:
54 friend class base::RefCountedThreadSafe<U2fMessage>;
55 FRIEND_TEST_ALL_PREFIXES(U2fMessageTest, TestMaxLengthPacketConstructors);
56 FRIEND_TEST_ALL_PREFIXES(U2fMessageTest, TestMessagePartioning);
57 FRIEND_TEST_ALL_PREFIXES(U2fMessageTest, TestDeconstruct);
58 FRIEND_TEST_ALL_PREFIXES(U2fMessageTest, TestMaxSize);
59 FRIEND_TEST_ALL_PREFIXES(U2fMessageTest, TestDeserialize);
60
61 static const size_t kInitPacketHeader = 7;
62 static const size_t kContinuationPacketHeader = 5;
63 static const size_t kMaxHidPacketSize = 64;
64 static const size_t kInitPacketDataSize =
65 kMaxHidPacketSize - kInitPacketHeader;
66 static const size_t kContinuationPacketDataSize =
67 kMaxHidPacketSize - kContinuationPacketHeader;
68 // Messages are limited to an init packet and 128 cont packets
69 // Maximum payload length therefore is 64-7 + 128 * (64-5) = 7609 bytes
70 static const size_t kMaxMessageSize = 7609;
71
72 U2fMessage(const uint32_t channel_id,
73 const Type type,
74 const std::vector<uint8_t>& data);
75 U2fMessage(scoped_refptr<net::IOBufferWithSize> buf);
76
77 std::list<scoped_refptr<U2fPacket>> packets_;
78 size_t remaining_size_;
79 uint32_t channel_id_;
80 };
81 } // namespace device
82
83 #endif // DEVICE_U2F_U2F_MESSAGE_H_
OLDNEW
« no previous file with comments | « device/u2f/DEPS ('k') | device/u2f/u2f_message.cc » ('j') | device/u2f/u2f_message.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698