Chromium Code Reviews| Index: remoting/protocol/pin_client_authenticator.cc |
| diff --git a/remoting/protocol/pin_client_authenticator.cc b/remoting/protocol/pin_client_authenticator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fe332c00a5022c2903848f39b7772e6354cee6de |
| --- /dev/null |
| +++ b/remoting/protocol/pin_client_authenticator.cc |
| @@ -0,0 +1,81 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/protocol/pin_client_authenticator.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/callback.h" |
| +#include "base/logging.h" |
| +#include "remoting/protocol/channel_authenticator.h" |
| +#include "remoting/protocol/pin_fetcher.h" |
| +#include "remoting/protocol/v2_authenticator.h" |
| +#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| + |
| +namespace remoting { |
| +namespace protocol { |
| + |
| +PinClientAuthenticator::PinClientAuthenticator( |
| + AuthenticationMethod::HashFunction hash_function, |
| + const std::string& authentication_tag, |
| + scoped_ptr<PinFetcher> pin_fetcher, |
| + Authenticator::State initial_state, |
| + const base::Closure& resume_callback) |
| + : hash_function_(hash_function), |
| + authentication_tag_(authentication_tag), |
| + pin_fetcher_(pin_fetcher.Pass()) { |
| + DCHECK(pin_fetcher_); |
| + pin_fetcher_->FetchPin(base::Bind( |
| + &PinClientAuthenticator::OnPinFetched, |
| + base::Unretained(this), initial_state, resume_callback)); |
| +} |
| + |
| +PinClientAuthenticator::~PinClientAuthenticator() { |
| +} |
| + |
| +Authenticator::State PinClientAuthenticator::state() const { |
| + DCHECK(underlying_); |
|
Sergey Ulanov
2013/03/17 21:29:21
What if this method is called before PIN is fetche
rmsousa
2013/03/18 21:07:26
That's illegal (hence the DCHECK).
NegotatingAuthe
|
| + return underlying_->state(); |
| +} |
| + |
| +Authenticator::RejectionReason |
| +PinClientAuthenticator::rejection_reason() const { |
| + DCHECK(underlying_); |
| + DCHECK_EQ(underlying_->state(), REJECTED); |
| + return underlying_->rejection_reason(); |
| +} |
| + |
| +void PinClientAuthenticator::ProcessMessage( |
| + const buzz::XmlElement* message, const base::Closure& resume_callback) { |
| + DCHECK(underlying_); |
| + underlying_->ProcessMessage(message, resume_callback); |
| +} |
| + |
| +void PinClientAuthenticator::OnPinFetched( |
| + Authenticator::State initial_state, |
| + const base::Closure& resume_callback, |
| + const std::string& shared_secret) { |
| + underlying_ = V2Authenticator::CreateForClient( |
| + AuthenticationMethod::ApplyHashFunction( |
| + hash_function_, authentication_tag_, shared_secret), |
| + initial_state); |
| + resume_callback.Run(); |
| +} |
| + |
| + |
| +scoped_ptr<buzz::XmlElement> PinClientAuthenticator::GetNextMessage() { |
| + DCHECK(underlying_); |
| + DCHECK_EQ(underlying_->state(), MESSAGE_READY); |
| + return underlying_->GetNextMessage(); |
| +} |
| + |
| +scoped_ptr<ChannelAuthenticator> |
| +PinClientAuthenticator::CreateChannelAuthenticator() const { |
| + DCHECK(underlying_); |
| + DCHECK_EQ(underlying_->state(), ACCEPTED); |
| + return underlying_->CreateChannelAuthenticator(); |
| +} |
| + |
| +} // namespace protocol |
| +} // namespace remoting |
| + |