Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/macros.h" | |
| 11 #include "device/u2f/u2f_packet.h" | |
| 12 | |
| 13 namespace device { | |
| 14 | |
| 15 // U2fMessages are defined by the specification at | |
| 16 // http://fidoalliance.org/specs/u2f-specs-1.0-bt-nfc-id-amendment/fido-u2f-hid- protocol.html | |
| 17 | |
| 18 class U2fMessage : public base::RefCountedThreadSafe<U2fMessage> { | |
| 19 public: | |
| 20 enum class Type : uint8_t { | |
| 21 CMD_PING = 0x81, | |
| 22 CMD_MSG = 0x83, | |
| 23 CMD_INIT = 0x86, | |
| 24 CMD_WINK = 0x88, | |
| 25 CMD_ERROR = 0xbf, | |
| 26 }; | |
| 27 | |
| 28 static const size_t kInitPacketHeader = 7; | |
|
juanlang (chromium.org)
2016/12/07 18:29:26
Nit: this, and the remaining constants, seem like
Casey Piper
2016/12/09 00:15:54
Done, moved to private and test classes were added
| |
| 29 static const size_t kContPacketHeader = 5; | |
|
juanlang (chromium.org)
2016/12/07 18:29:26
Nit: prefer Continuation to Cont.
Casey Piper
2016/12/09 00:15:54
Done.
| |
| 30 static const size_t kMaxHidPacketSize = 64; | |
| 31 static const size_t kInitPacketDataSize = | |
| 32 kMaxHidPacketSize - kInitPacketHeader; | |
| 33 static const size_t kContPacketDataSize = | |
| 34 kMaxHidPacketSize - kContPacketHeader; | |
| 35 // Messages are limited to an init packet and 128 cont packets | |
| 36 // Maximum payload length therefore is 64-7 + 128 * (64-5) = 7609 bytes | |
| 37 static const size_t kMaxMessageSize = 7609; | |
| 38 | |
| 39 static scoped_refptr<U2fMessage> Create( | |
| 40 const uint8_t channel_id[U2fPacket::kChannelIdSize], | |
|
juanlang (chromium.org)
2016/12/07 18:29:26
Passing arrays as parameters in C is a little dice
Casey Piper
2016/12/09 00:15:54
Done.
| |
| 41 const Type type, | |
| 42 const std::vector<uint8_t>& data); | |
| 43 static scoped_refptr<U2fMessage> Create( | |
|
juanlang (chromium.org)
2016/12/07 18:29:26
This method name makes it a little hard to differe
Casey Piper
2016/12/09 00:15:54
Create method names changed for clarity.
| |
| 44 scoped_refptr<net::IOBufferWithSize> buf); | |
| 45 scoped_refptr<net::IOBufferWithSize> PopNextPacket(); | |
| 46 bool AddContPacket(scoped_refptr<net::IOBufferWithSize> packet_buf); | |
| 47 size_t NumPackets(); | |
| 48 const std::vector<uint8_t> GetData(); | |
| 49 const uint8_t* GetChannelId(); | |
| 50 bool MessageComplete(); | |
| 51 std::list<scoped_refptr<U2fPacket>>::const_iterator begin(); | |
| 52 std::list<scoped_refptr<U2fPacket>>::const_iterator end(); | |
| 53 | |
| 54 protected: | |
| 55 virtual ~U2fMessage(); | |
| 56 | |
| 57 private: | |
| 58 friend class base::RefCountedThreadSafe<U2fMessage>; | |
| 59 | |
| 60 U2fMessage(const uint8_t channel_id[U2fPacket::kChannelIdSize], | |
| 61 const Type type, | |
| 62 const std::vector<uint8_t>& data); | |
| 63 U2fMessage(scoped_refptr<net::IOBufferWithSize> buf); | |
| 64 | |
| 65 std::list<scoped_refptr<U2fPacket>> packets_; | |
| 66 size_t remaining_size_; | |
| 67 uint8_t channel_id_[U2fPacket::kChannelIdSize]; | |
| 68 }; | |
| 69 } // namespace device | |
| 70 | |
| 71 #endif // DEVICE_U2F_U2F_MESSAGE_H_ | |
| OLD | NEW |