mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
introduce authentication transport function into DeviceProvider
PiperOrigin-RevId: 538909999
This commit is contained in:
committed by
Copybara-Service
parent
472fba64ae
commit
1c455e3488
@@ -26,6 +26,11 @@ namespace {
|
||||
constexpr absl::string_view kEndpointId = "ABCD";
|
||||
constexpr absl::string_view kEndpointInfo = "NC endpoint";
|
||||
|
||||
class MockAuthenticationTransport : public AuthenticationTransport {
|
||||
MOCK_METHOD(void, WriteMessage, (absl::string_view), (const override));
|
||||
MOCK_METHOD(std::string, ReadMessage, (), (const override));
|
||||
};
|
||||
|
||||
TEST(ConnectionsDeviceProviderTest, TestProviderWorksTwoArgs) {
|
||||
ConnectionsDeviceProvider provider(kEndpointInfo, {});
|
||||
auto device = provider.GetLocalDevice();
|
||||
@@ -46,6 +51,16 @@ TEST(ConnectionsDeviceProviderTest, TestProviderWorksThreeArgs) {
|
||||
EXPECT_EQ(connections_device->GetEndpointId(), kEndpointId);
|
||||
}
|
||||
|
||||
TEST(ConnectionsDeviceProviderTest, TestUnknownAuthStatus) {
|
||||
ConnectionsDeviceProvider provider(kEndpointId, kEndpointInfo, {});
|
||||
MockAuthenticationTransport transport;
|
||||
EXPECT_EQ(provider.AuthenticateConnection(/*local_device=*/nullptr,
|
||||
/*remote_device=*/nullptr,
|
||||
AuthenticationRole::kInitiator,
|
||||
/*shared_secret=*/"", transport),
|
||||
AuthenticationStatus::kUnknown);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace v3
|
||||
} // namespace connections
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
cc_library(
|
||||
name = "authentication_transport_interface",
|
||||
hdrs = [
|
||||
"authentication_transport.h",
|
||||
],
|
||||
visibility = [
|
||||
"//:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "device",
|
||||
hdrs = [
|
||||
@@ -9,6 +22,7 @@ cc_library(
|
||||
"//presence:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
":authentication_transport_interface",
|
||||
"//internal/platform:connection_info",
|
||||
"//internal/platform:types",
|
||||
"@com_google_absl//absl/strings",
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright 2023 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_INTERNAL_INTEROP_AUTHENTICATION_TRANSPORT_H_
|
||||
#define THIRD_PARTY_NEARBY_INTERNAL_INTEROP_AUTHENTICATION_TRANSPORT_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
class AuthenticationTransport {
|
||||
public:
|
||||
virtual ~AuthenticationTransport() = default;
|
||||
virtual void WriteMessage(absl::string_view message) const = 0;
|
||||
virtual std::string ReadMessage() const = 0;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_INTERNAL_INTEROP_AUTHENTICATION_TRANSPORT_H_
|
||||
@@ -15,10 +15,23 @@
|
||||
#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_DEVICE_PROVIDER_H_
|
||||
#define THIRD_PARTY_NEARBY_CONNECTIONS_DEVICE_PROVIDER_H_
|
||||
|
||||
#include "internal/interop/authentication_transport.h"
|
||||
#include "internal/interop/device.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
enum class AuthenticationRole {
|
||||
kUnknown = 0,
|
||||
kInitiator = 1,
|
||||
kReceiver = 2,
|
||||
};
|
||||
|
||||
enum class AuthenticationStatus {
|
||||
kUnknown = 0,
|
||||
kSuccess = 1,
|
||||
kFailure = 2,
|
||||
};
|
||||
|
||||
// The base device provider class for use with the Nearby Connections V3 APIs.
|
||||
// This class currently provides a function to get the local device for whatever
|
||||
// client implements it.
|
||||
@@ -27,6 +40,13 @@ class NearbyDeviceProvider {
|
||||
virtual ~NearbyDeviceProvider() = default;
|
||||
|
||||
const virtual NearbyDevice* GetLocalDevice() = 0;
|
||||
virtual AuthenticationStatus AuthenticateConnection(
|
||||
NearbyDevice* local_device, NearbyDevice* remote_device,
|
||||
AuthenticationRole role, absl::string_view shared_secret,
|
||||
const AuthenticationTransport& authentication_transport) const {
|
||||
// We want to check out-of-band by default (Show UKEY2 digits to user).
|
||||
return AuthenticationStatus::kUnknown;
|
||||
}
|
||||
};
|
||||
} // namespace nearby
|
||||
|
||||
|
||||
@@ -28,6 +28,13 @@ class PresenceDeviceProvider : public NearbyDeviceProvider {
|
||||
: device_{metadata} {}
|
||||
|
||||
const NearbyDevice* GetLocalDevice() override { return &device_; }
|
||||
AuthenticationStatus AuthenticateConnection(
|
||||
NearbyDevice* local_device, NearbyDevice* remote_device,
|
||||
AuthenticationRole role, absl::string_view shared_secret,
|
||||
const AuthenticationTransport& authentication_transport) const override {
|
||||
// TODO(b/282027237): Implement.
|
||||
return AuthenticationStatus::kUnknown;
|
||||
}
|
||||
|
||||
void UpdateMetadata(const ::nearby::internal::Metadata& metadata) {
|
||||
device_.SetMetadata(metadata);
|
||||
|
||||
Reference in New Issue
Block a user