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

Side by Side Diff: chrome/browser/local_discovery/privetv3_crypto_provider.cc

Issue 316873004: Interface plus stub implementation for PrivetV3CryptoProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/local_discovery/privetv3_crypto_provider.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 virtual ~PrivetV3CryptoProviderEmpty();
24
25 // PrivetV3CryptoProvider implementation.
26 virtual HandshakeState GetState() OVERRIDE;
27 virtual std::string GetAuthMethod() OVERRIDE;
28 virtual HandshakeState GetNextStep(int* step, std::string* package) OVERRIDE;
29 virtual HandshakeState SetStepResponse(int step,
30 const std::string& state,
31 const std::string& package) OVERRIDE;
32 virtual std::string GetVerificationCode() OVERRIDE;
33 virtual HandshakeState AcceptVerificationCode() OVERRIDE;
34 virtual bool EncryptData(const std::string& input,
35 std::string* output) OVERRIDE;
36
37 private:
38 HandshakeState state_;
39 };
40
41 scoped_ptr<PrivetV3CryptoProvider> Create(
42 const std::vector<std::string>& available_auth_methods) {
43 for (size_t i = 0; i < available_auth_methods.size(); i++) {
44 if (available_auth_methods[i] == kAuthMethodEmpty) {
45 return scoped_ptr<PrivetV3CryptoProvider>(
46 new PrivetV3CryptoProviderEmpty());
47 }
48 }
49
50 return scoped_ptr<PrivetV3CryptoProvider>();
51 }
52
53 PrivetV3CryptoProviderEmpty::PrivetV3CryptoProviderEmpty()
54 : state_(IN_PROGRESS) {
55 }
56
57 PrivetV3CryptoProviderEmpty::~PrivetV3CryptoProviderEmpty() {
58 }
59
60 PrivetV3CryptoProvider::HandshakeState PrivetV3CryptoProviderEmpty::GetState() {
61 return state_;
62 }
63
64 std::string PrivetV3CryptoProviderEmpty::GetAuthMethod() {
65 return kAuthMethodEmpty;
66 }
67
68 PrivetV3CryptoProvider::HandshakeState PrivetV3CryptoProviderEmpty::GetNextStep(
69 int* step,
70 std::string* package) {
71 DCHECK(state_ == IN_PROGRESS);
72 *step = 0;
73 package->clear();
74 state_ = AWAITING_RESPONSE;
75
76 return state_;
77 }
78
79 PrivetV3CryptoProvider::HandshakeState
80 PrivetV3CryptoProviderEmpty::SetStepResponse(int step,
81 const std::string& state,
82 const std::string& package) {
83 DCHECK(state_ == AWAITING_RESPONSE);
84
85 bool success =
86 (step == 0 && package.empty() && state == kHandshakeStateComplete);
87
88 if (success) {
89 state_ = AWAITING_USER_VERIFICATION;
90 } else {
91 state_ = HANDSHAKE_ERROR;
92 }
93
94 return state_;
95 }
96
97 std::string PrivetV3CryptoProviderEmpty::GetVerificationCode() {
98 DCHECK(state_ == AWAITING_USER_VERIFICATION);
99 return kStubVerificationCode;
100 }
101
102 PrivetV3CryptoProvider::HandshakeState
103 PrivetV3CryptoProviderEmpty::AcceptVerificationCode() {
104 DCHECK(state_ == AWAITING_USER_VERIFICATION);
105 return (state_ = HANDSHAKE_COMPLETE);
106 }
107
108 bool PrivetV3CryptoProviderEmpty::EncryptData(const std::string& input,
109 std::string* output) {
110 *output = input;
111 return true;
112 }
113
114 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privetv3_crypto_provider.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698