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.
5 #include "chrome/browser/local_discovery/privetv3_crypto_provider.h"
7 #include "base/logging.h"
9 namespace local_discovery
{
13 // A stub session type used for development/debugging.
14 const char kAuthMethodEmpty
[] = "empty";
16 const char kHandshakeStateComplete
[] = "complete";
17 const char kStubVerificationCode
[] = "SAMPLE";
20 class PrivetV3CryptoProviderEmpty
: public PrivetV3CryptoProvider
{
22 PrivetV3CryptoProviderEmpty();
23 ~PrivetV3CryptoProviderEmpty() override
;
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
;
37 HandshakeState state_
;
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());
49 return scoped_ptr
<PrivetV3CryptoProvider
>();
52 PrivetV3CryptoProviderEmpty::PrivetV3CryptoProviderEmpty()
53 : state_(IN_PROGRESS
) {
56 PrivetV3CryptoProviderEmpty::~PrivetV3CryptoProviderEmpty() {
59 PrivetV3CryptoProvider::HandshakeState
PrivetV3CryptoProviderEmpty::GetState() {
63 std::string
PrivetV3CryptoProviderEmpty::GetAuthMethod() {
64 return kAuthMethodEmpty
;
67 PrivetV3CryptoProvider::HandshakeState
PrivetV3CryptoProviderEmpty::GetNextStep(
69 std::string
* package
) {
70 DCHECK(state_
== IN_PROGRESS
);
73 state_
= AWAITING_RESPONSE
;
78 PrivetV3CryptoProvider::HandshakeState
79 PrivetV3CryptoProviderEmpty::SetStepResponse(int step
,
80 const std::string
& state
,
81 const std::string
& package
) {
82 DCHECK(state_
== AWAITING_RESPONSE
);
85 (step
== 0 && package
.empty() && state
== kHandshakeStateComplete
);
88 state_
= AWAITING_USER_VERIFICATION
;
90 state_
= HANDSHAKE_ERROR
;
96 std::string
PrivetV3CryptoProviderEmpty::GetVerificationCode() {
97 DCHECK(state_
== AWAITING_USER_VERIFICATION
);
98 return kStubVerificationCode
;
101 PrivetV3CryptoProvider::HandshakeState
102 PrivetV3CryptoProviderEmpty::AcceptVerificationCode() {
103 DCHECK(state_
== AWAITING_USER_VERIFICATION
);
104 return (state_
= HANDSHAKE_COMPLETE
);
107 bool PrivetV3CryptoProviderEmpty::EncryptData(const std::string
& input
,
108 std::string
* output
) {
113 } // namespace local_discovery