OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 #include "chrome/browser/local_discovery/privetv3_crypto_provider.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 namespace local_discovery { | |
10 | |
11 namespace { | |
12 | |
13 // A stub session type used for development/debugging. | |
14 const char kAuthMethodEmpty[] = "empty"; | |
15 | |
16 const char kHandshakeStateComplete[] = "complete"; | |
17 const char kStubVerificationCode[] = "SAMPLE"; | |
18 } | |
19 | |
20 class PrivetV3CryptoProviderEmpty : public PrivetV3CryptoProvider { | |
21 public: | |
22 PrivetV3CryptoProviderEmpty(); | |
23 ~PrivetV3CryptoProviderEmpty() override; | |
24 | |
25 // PrivetV3CryptoProvider implementation. | |
26 HandshakeState GetState() override; | |
27 std::string GetAuthMethod() override; | |
28 HandshakeState GetNextStep(int* step, std::string* package) override; | |
29 HandshakeState SetStepResponse(int step, | |
30 const std::string& state, | |
31 const std::string& package) override; | |
32 std::string GetVerificationCode() override; | |
33 HandshakeState AcceptVerificationCode() override; | |
34 bool EncryptData(const std::string& input, std::string* output) override; | |
35 | |
36 private: | |
37 HandshakeState state_; | |
38 }; | |
39 | |
40 scoped_ptr<PrivetV3CryptoProvider> Create( | |
41 const std::vector<std::string>& available_auth_methods) { | |
42 for (size_t i = 0; i < available_auth_methods.size(); i++) { | |
43 if (available_auth_methods[i] == kAuthMethodEmpty) { | |
44 return scoped_ptr<PrivetV3CryptoProvider>( | |
45 new PrivetV3CryptoProviderEmpty()); | |
46 } | |
47 } | |
48 | |
49 return scoped_ptr<PrivetV3CryptoProvider>(); | |
50 } | |
51 | |
52 PrivetV3CryptoProviderEmpty::PrivetV3CryptoProviderEmpty() | |
53 : state_(IN_PROGRESS) { | |
54 } | |
55 | |
56 PrivetV3CryptoProviderEmpty::~PrivetV3CryptoProviderEmpty() { | |
57 } | |
58 | |
59 PrivetV3CryptoProvider::HandshakeState PrivetV3CryptoProviderEmpty::GetState() { | |
60 return state_; | |
61 } | |
62 | |
63 std::string PrivetV3CryptoProviderEmpty::GetAuthMethod() { | |
64 return kAuthMethodEmpty; | |
65 } | |
66 | |
67 PrivetV3CryptoProvider::HandshakeState PrivetV3CryptoProviderEmpty::GetNextStep( | |
68 int* step, | |
69 std::string* package) { | |
70 DCHECK(state_ == IN_PROGRESS); | |
71 *step = 0; | |
72 package->clear(); | |
73 state_ = AWAITING_RESPONSE; | |
74 | |
75 return state_; | |
76 } | |
77 | |
78 PrivetV3CryptoProvider::HandshakeState | |
79 PrivetV3CryptoProviderEmpty::SetStepResponse(int step, | |
80 const std::string& state, | |
81 const std::string& package) { | |
82 DCHECK(state_ == AWAITING_RESPONSE); | |
83 | |
84 bool success = | |
85 (step == 0 && package.empty() && state == kHandshakeStateComplete); | |
86 | |
87 if (success) { | |
88 state_ = AWAITING_USER_VERIFICATION; | |
89 } else { | |
90 state_ = HANDSHAKE_ERROR; | |
91 } | |
92 | |
93 return state_; | |
94 } | |
95 | |
96 std::string PrivetV3CryptoProviderEmpty::GetVerificationCode() { | |
97 DCHECK(state_ == AWAITING_USER_VERIFICATION); | |
98 return kStubVerificationCode; | |
99 } | |
100 | |
101 PrivetV3CryptoProvider::HandshakeState | |
102 PrivetV3CryptoProviderEmpty::AcceptVerificationCode() { | |
103 DCHECK(state_ == AWAITING_USER_VERIFICATION); | |
104 return (state_ = HANDSHAKE_COMPLETE); | |
105 } | |
106 | |
107 bool PrivetV3CryptoProviderEmpty::EncryptData(const std::string& input, | |
108 std::string* output) { | |
109 *output = input; | |
110 return true; | |
111 } | |
112 | |
113 } // namespace local_discovery | |
OLD | NEW |