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

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

Issue 2821263005: Add U2F request state machines (Closed)
Patch Set: Add U2fRequest, U2fSign, and U2fRegister classes Created 3 years, 8 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_REQUEST_H_
6 #define DEVICE_U2F_U2F_REQUEST_H_
7
8 #include "base/cancelable_callback.h"
9 #include "base/scoped_observer.h"
10 #include "device/hid/hid_device_filter.h"
11 #include "device/hid/hid_service.h"
12 #include "u2f_device.h"
13
14 namespace device {
15 class U2fRequest : HidService::Observer {
16 public:
17 using ResponseCallback =
18 base::Callback<void(uint8_t status_code, std::vector<uint8_t> response)>;
19
20 U2fRequest(const ResponseCallback& callback);
21 virtual ~U2fRequest();
22
23 void Start();
24
25 protected:
26 enum class State {
27 INIT,
28 BUSY,
29 WINK,
30 IDLE,
31 OFF,
32 COMPLETE,
33 };
34
35 void Transition();
36 virtual void TryDevice() = 0;
37
38 std::unique_ptr<U2fDevice> current_device_;
39 State state_;
40 const ResponseCallback& cb_;
Reilly Grant (use Gerrit) 2017/04/21 17:19:16 This should not be a reference as there is no guar
Casey Piper 2017/04/21 22:55:16 Done.
41
42 private:
43 FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestAddRemoveDevice);
44 FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestIterateDevice);
45 FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestBasicMachine);
46 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestSimpleSign);
47 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestMultipleHandles);
48 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestSignSuccess);
49 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestDelayedSuccess);
50 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestMultipleDevices);
51 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestFakeEnroll);
52 FRIEND_TEST_ALL_PREFIXES(U2fRegisterTest, TestRegisterSuccess);
53 FRIEND_TEST_ALL_PREFIXES(U2fRegisterTest, TestDelayedSuccess);
54 FRIEND_TEST_ALL_PREFIXES(U2fRegisterTest, TestMultipleDevices);
55
56 void Enumerate();
57 void IterateDevice();
58 void OnWaitComplete();
59 void OnDeviceAdded(scoped_refptr<HidDeviceInfo> device_info) override;
60 void OnDeviceRemoved(scoped_refptr<HidDeviceInfo> device_info) override;
61 void OnEnumerate(const std::vector<scoped_refptr<HidDeviceInfo>>& devices);
62
63 std::list<std::unique_ptr<U2fDevice>> devices_;
64 std::list<std::unique_ptr<U2fDevice>> attempted_devices_;
65 base::CancelableClosure delay_callback_;
66 HidDeviceFilter filter_;
67 ScopedObserver<HidService, HidService::Observer> hid_service_observer_;
68 base::WeakPtrFactory<U2fRequest> weak_factory_;
69 };
70 } // namespace device
71
72 #endif // DEVICE_U2F_U2F_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698