Commit 51b28b64 authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Convert Authenticator to BindOnce/OnceCallback

Bug: 1007662
Change-Id: I31c5de09e2e0e18daf316b519a86cdabdb50be11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2375005Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801688}
parent 04c880cb
......@@ -39,10 +39,10 @@ class Authenticator {
// If the authentication protocol succeeds, then |secure_context| will be
// contain the SecureContext used to securely exchange messages. Otherwise, it
// will be null if the protocol fails.
typedef base::Callback<void(Result result,
std::unique_ptr<SecureContext> secure_context)>
typedef base::OnceCallback<
void(Result result, std::unique_ptr<SecureContext> secure_context)>
AuthenticationCallback;
virtual void Authenticate(const AuthenticationCallback& callback) = 0;
virtual void Authenticate(AuthenticationCallback callback) = 0;
};
} // namespace secure_channel
......
......@@ -71,15 +71,15 @@ DeviceToDeviceAuthenticator::~DeviceToDeviceAuthenticator() {
}
void DeviceToDeviceAuthenticator::Authenticate(
const AuthenticationCallback& callback) {
AuthenticationCallback callback) {
if (state_ != State::NOT_STARTED) {
PA_LOG(ERROR)
<< "Authenticator was already used. Do not reuse this instance!";
callback.Run(Result::FAILURE, nullptr);
std::move(callback).Run(Result::FAILURE, nullptr);
return;
}
callback_ = callback;
callback_ = std::move(callback);
if (!connection_->IsConnected()) {
Fail("Not connected to remote device", Result::DISCONNECTED);
return;
......@@ -90,7 +90,7 @@ void DeviceToDeviceAuthenticator::Authenticate(
// Generate a key-pair for this individual session.
state_ = State::GENERATING_SESSION_KEYS;
secure_message_delegate_->GenerateKeyPair(
base::Bind(&DeviceToDeviceAuthenticator::OnKeyPairGenerated,
base::BindOnce(&DeviceToDeviceAuthenticator::OnKeyPairGenerated,
weak_ptr_factory_.GetWeakPtr()));
}
......@@ -109,7 +109,7 @@ void DeviceToDeviceAuthenticator::OnKeyPairGenerated(
helper_->CreateHelloMessage(
public_key, connection_->remote_device().persistent_symmetric_key(),
secure_message_delegate_.get(),
base::Bind(&DeviceToDeviceAuthenticator::OnHelloMessageCreated,
base::BindOnce(&DeviceToDeviceAuthenticator::OnHelloMessageCreated,
weak_ptr_factory_.GetWeakPtr()));
}
......@@ -163,7 +163,7 @@ void DeviceToDeviceAuthenticator::OnResponderAuthValidated(
helper_->CreateInitiatorAuthMessage(
session_keys_, connection_->remote_device().persistent_symmetric_key(),
responder_auth_message_, secure_message_delegate_.get(),
base::Bind(&DeviceToDeviceAuthenticator::OnInitiatorAuthCreated,
base::BindOnce(&DeviceToDeviceAuthenticator::OnInitiatorAuthCreated,
weak_ptr_factory_.GetWeakPtr()));
}
......@@ -192,7 +192,7 @@ void DeviceToDeviceAuthenticator::Fail(const std::string& error_message,
weak_ptr_factory_.InvalidateWeakPtrs();
connection_->RemoveObserver(this);
timer_.reset();
callback_.Run(result, nullptr);
std::move(callback_).Run(result, nullptr);
}
void DeviceToDeviceAuthenticator::Succeed() {
......@@ -203,7 +203,7 @@ void DeviceToDeviceAuthenticator::Succeed() {
state_ = State::AUTHENTICATION_SUCCESS;
connection_->RemoveObserver(this);
callback_.Run(
std::move(callback_).Run(
Result::SUCCESS,
std::make_unique<DeviceToDeviceSecureContext>(
std::move(secure_message_delegate_), session_keys_,
......@@ -240,7 +240,7 @@ void DeviceToDeviceAuthenticator::OnMessageReceived(
connection_->remote_device().persistent_symmetric_key(),
local_session_private_key_, hello_message_,
secure_message_delegate_.get(),
base::Bind(&DeviceToDeviceAuthenticator::OnResponderAuthValidated,
base::BindOnce(&DeviceToDeviceAuthenticator::OnResponderAuthValidated,
weak_ptr_factory_.GetWeakPtr()));
} else {
Fail("Unexpected message received");
......
......@@ -80,7 +80,7 @@ class DeviceToDeviceAuthenticator : public Authenticator,
~DeviceToDeviceAuthenticator() override;
// Authenticator:
void Authenticate(const AuthenticationCallback& callback) override;
void Authenticate(AuthenticationCallback callback) override;
protected:
// Creates a base::OneShotTimer instance. Exposed for testing.
......
......@@ -163,13 +163,13 @@ class SecureChannelDeviceToDeviceAuthenticatorTest : public testing::Test {
secure_message_delegate_->DeriveKey(
remote_session_private_key_, local_session_public_key_,
base::Bind(&SaveStringResult, &session_symmetric_key_));
base::BindOnce(&SaveStringResult, &session_symmetric_key_));
}
// Begins authentication, and returns the [Hello] message sent from the local
// device to the remote device.
std::string BeginAuthentication() {
authenticator_.Authenticate(base::Bind(
authenticator_.Authenticate(base::BindOnce(
&SecureChannelDeviceToDeviceAuthenticatorTest::OnAuthenticationResult,
base::Unretained(this)));
......@@ -182,7 +182,7 @@ class SecureChannelDeviceToDeviceAuthenticatorTest : public testing::Test {
DeviceToDeviceResponderOperations::ValidateHelloMessage(
hello_message, remote_device_.persistent_symmetric_key(),
secure_message_delegate_,
base::Bind(&SaveValidateHelloMessageResult, &validated,
base::BindOnce(&SaveValidateHelloMessageResult, &validated,
&local_session_public_key));
EXPECT_TRUE(validated);
......@@ -202,7 +202,7 @@ class SecureChannelDeviceToDeviceAuthenticatorTest : public testing::Test {
hello_message, remote_session_public_key_, remote_session_private_key_,
remote_device_private_key, remote_device_.persistent_symmetric_key(),
secure_message_delegate_,
base::Bind(&SaveStringResult, &responder_auth_message));
base::BindOnce(&SaveStringResult, &responder_auth_message));
EXPECT_FALSE(responder_auth_message.empty());
WireMessage wire_message(responder_auth_message,
......@@ -264,7 +264,7 @@ TEST_F(SecureChannelDeviceToDeviceAuthenticatorTest, AuthenticateSucceeds) {
initiator_auth, SessionKeys(session_symmetric_key_),
remote_device_.persistent_symmetric_key(), responder_auth_message,
secure_message_delegate_,
base::Bind(&SaveBooleanResult, &initiator_auth_validated));
base::BindOnce(&SaveBooleanResult, &initiator_auth_validated));
ASSERT_TRUE(initiator_auth_validated);
}
......@@ -304,7 +304,7 @@ TEST_F(SecureChannelDeviceToDeviceAuthenticatorTest, NotConnectedInitially) {
connection_.Disconnect();
EXPECT_CALL(*this,
OnAuthenticationResultProxy(Authenticator::Result::DISCONNECTED));
authenticator_.Authenticate(base::Bind(
authenticator_.Authenticate(base::BindOnce(
&SecureChannelDeviceToDeviceAuthenticatorTest::OnAuthenticationResult,
base::Unretained(this)));
EXPECT_FALSE(secure_context_);
......@@ -314,7 +314,7 @@ TEST_F(SecureChannelDeviceToDeviceAuthenticatorTest, FailToSendHello) {
connection_.set_connection_blocked(true);
EXPECT_CALL(*this,
OnAuthenticationResultProxy(Authenticator::Result::FAILURE));
authenticator_.Authenticate(base::Bind(
authenticator_.Authenticate(base::BindOnce(
&SecureChannelDeviceToDeviceAuthenticatorTest::OnAuthenticationResult,
base::Unretained(this)));
EXPECT_FALSE(secure_context_);
......
......@@ -15,8 +15,8 @@ FakeAuthenticator::FakeAuthenticator() {}
FakeAuthenticator::~FakeAuthenticator() {}
void FakeAuthenticator::Authenticate(
const Authenticator::AuthenticationCallback& callback) {
last_callback_ = callback;
Authenticator::AuthenticationCallback callback) {
last_callback_ = std::move(callback);
}
} // namespace secure_channel
......
......@@ -20,9 +20,9 @@ class FakeAuthenticator : public Authenticator {
~FakeAuthenticator() override;
// Authenticator:
void Authenticate(const AuthenticationCallback& callback) override;
void Authenticate(AuthenticationCallback callback) override;
AuthenticationCallback last_callback() { return last_callback_; }
AuthenticationCallback last_callback() { return std::move(last_callback_); }
private:
AuthenticationCallback last_callback_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment