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

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

Issue 2721223002: Add support for U2fHidDevice interaction (Closed)
Patch Set: Modify unittest BUILD file Created 3 years, 9 months 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 2017 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_HID_DEVICE_H_
6 #define DEVICE_U2F_U2F_HID_DEVICE_H_
7
8 #include "device/hid/hid_service.h"
9 #include "u2f_device.h"
10
11 namespace net {
12 class IOBuffer;
13 } // namespace net
14
15 namespace device {
16
17 class U2fMessage;
18 class HidConnection;
19 class HidDeviceInfo;
20
21 class U2fHidDevice : public U2fDevice {
22 public:
23 U2fHidDevice(scoped_refptr<HidDeviceInfo>);
24 ~U2fHidDevice();
25
26 // Send a U2f command to this device
27 void DeviceTransact(scoped_refptr<U2fApduCommand> command,
28 const DeviceCallback& callback) final;
29 // Send a wink command if supported
30 void TryWink(const WinkCallback& callback) final;
31 // Use a string identifier to compare to other devices
32 std::string Id() final;
33 // Command line flag to enable tests on actual U2f HID hardware
34 static bool IsTestEnabled();
35
36 private:
37 // Internal state machine states
38 enum class State { INIT, CONNECTED, IDLE, DEVICE_ERROR };
39
40 using U2fHidMessageCallback =
41 base::Callback<void(bool, scoped_refptr<U2fMessage>)>;
42
43 // Open a connection to this device
44 void Connect(const HidService::ConnectCallback& callback);
45 void OnConnect(scoped_refptr<U2fApduCommand> command,
46 const DeviceCallback& callback,
47 scoped_refptr<HidConnection> connection);
48 // Ask device to allocate a unique channel id for this connection
49 void AllocateChannel(scoped_refptr<U2fApduCommand> command,
50 const DeviceCallback& callback);
51 void OnAllocateChannel(std::vector<uint8_t> nonce,
52 scoped_refptr<U2fApduCommand> command,
53 const DeviceCallback& callback,
54 bool success,
55 scoped_refptr<U2fMessage> message);
56 void Transition(scoped_refptr<U2fApduCommand> command,
57 const DeviceCallback& callback);
58 // Write all message packets to device, and read response if expected
59 void WriteMessage(scoped_refptr<U2fMessage> message,
60 bool response_expected,
61 const U2fHidMessageCallback&);
62 void PacketWritten(scoped_refptr<U2fMessage> message,
63 bool response_expected,
64 const U2fHidMessageCallback& callback,
65 bool success);
66 // Read all response message packets from device
67 void ReadMessage(const U2fHidMessageCallback& callback);
68 void MessageReceived(const DeviceCallback& callback,
69 bool success,
70 scoped_refptr<U2fMessage> message);
71 void OnRead(const U2fHidMessageCallback& callback,
72 bool success,
73 scoped_refptr<net::IOBuffer> buf,
74 size_t size);
75 void OnReadContinuation(scoped_refptr<U2fMessage> message,
76 const U2fHidMessageCallback&,
77 bool success,
78 scoped_refptr<net::IOBuffer> buf,
79 size_t size);
80 void OnWink(const WinkCallback& callback,
81 bool success,
82 scoped_refptr<U2fMessage> response);
83
84 State state_;
85 scoped_refptr<HidDeviceInfo> device_info_;
86 scoped_refptr<HidConnection> connection_;
87 base::WeakPtrFactory<U2fHidDevice> weak_factory_;
88
89 DISALLOW_COPY_AND_ASSIGN(U2fHidDevice);
90 };
91 }
Reilly Grant (use Gerrit) 2017/03/01 22:48:33 nit: newline and // namespace device
Casey Piper 2017/03/04 02:06:28 Done.
92
93 #endif // DEVICE_U2F_U2F_HID_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698