mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Make CredentialManager abstract
An abstract CredentialManager will help with unit testing. Also added an empty CredentialManagerImpl class. PiperOrigin-RevId: 463651261
This commit is contained in:
committed by
Copybara-Service
parent
c40a669755
commit
be140a71d5
@@ -70,6 +70,7 @@ cc_library(
|
||||
"//internal/platform:__pkg__",
|
||||
"//internal/platform/implementation:__subpackages__",
|
||||
"//third_party/nearby/presence:__pkg__",
|
||||
"//third_party/nearby/presence/implementation:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
"//connections/clients/windows:types",
|
||||
|
||||
@@ -19,6 +19,7 @@ cc_library(
|
||||
hdrs = [
|
||||
"broadcast_manager.h",
|
||||
"credential_manager.h",
|
||||
"credential_manager_impl.h",
|
||||
"mock_service_controller.h",
|
||||
"scan_manager.h",
|
||||
"service_controller.h",
|
||||
@@ -28,9 +29,12 @@ cc_library(
|
||||
"//third_party/nearby/presence:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:comm",
|
||||
"//internal/platform/implementation:comm",
|
||||
"//third_party/nearby/presence:credential",
|
||||
"//third_party/nearby/presence/implementation/mediums",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -19,15 +19,16 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "internal/platform/credential_storage.h"
|
||||
#include "absl/status/statusor.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/implementation/credential_storage.h"
|
||||
#include "third_party/nearby/presence/credential.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
|
||||
struct GenerateCredentialsCallback {
|
||||
std::function<void(std::vector<PublicCredential>)>
|
||||
credentials_generated_cb;
|
||||
std::function<void(std::vector<PublicCredential>)> credentials_generated_cb;
|
||||
};
|
||||
|
||||
struct UpdateRemotePublicCredentialsCallback {
|
||||
@@ -43,7 +44,7 @@ struct UpdateRemotePublicCredentialsCallback {
|
||||
class CredentialManager {
|
||||
public:
|
||||
CredentialManager() = default;
|
||||
~CredentialManager() = default;
|
||||
virtual ~CredentialManager() = default;
|
||||
|
||||
// Used to (re)generate user’s private and public credentials.
|
||||
// The generated private credentials will be saved to creds storage.
|
||||
@@ -51,28 +52,32 @@ class CredentialManager {
|
||||
// credentials_generated_cb for manager app to upload to web.
|
||||
// The user’s own public credentials won’t be saved on local credential
|
||||
// storage.
|
||||
void GenerateCredentials(
|
||||
virtual void GenerateCredentials(
|
||||
proto::DeviceMetadata device_metadata, std::vector<TrustType> trust_types,
|
||||
GenerateCredentialsCallback credentials_generated_cb);
|
||||
GenerateCredentialsCallback credentials_generated_cb) = 0;
|
||||
|
||||
// Update remote public credentials.
|
||||
void UpdateRemotePublicCredentials(
|
||||
virtual void UpdateRemotePublicCredentials(
|
||||
std::string account_name,
|
||||
std::vector<PublicCredential> remote_public_creds,
|
||||
UpdateRemotePublicCredentialsCallback credentials_updated_cb);
|
||||
UpdateRemotePublicCredentialsCallback credentials_updated_cb) = 0;
|
||||
|
||||
// Used to fetch private creds when broadcasting.
|
||||
void GetPrivateCredentials(
|
||||
virtual void GetPrivateCredentials(
|
||||
location::nearby::api::CredentialSelector credential_selector,
|
||||
location::nearby::api::GetPrivateCredentialCallback callback);
|
||||
location::nearby::api::GetPrivateCredentialCallback callback) = 0;
|
||||
|
||||
// Used to fetch remote public creds when scanning.
|
||||
void GetPublicCredentials(
|
||||
virtual void GetPublicCredentials(
|
||||
location::nearby::api::CredentialSelector credential_selector,
|
||||
location::nearby::api::GetPublicCredentialCallback callback);
|
||||
location::nearby::api::GetPublicCredentialCallback callback) = 0;
|
||||
|
||||
private:
|
||||
location::nearby::CredentialStorage* credential_storage_;
|
||||
// Decrypts Data Elements from an NP advertisement.
|
||||
// Returns an error if `metadata_key` is not associated with any known
|
||||
// credentials (identity).
|
||||
virtual absl::StatusOr<std::string> DecryptDataElements(
|
||||
absl::string_view metadata_key, absl::string_view salt,
|
||||
absl::string_view data_elements) = 0;
|
||||
};
|
||||
|
||||
} // namespace presence
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright 2022 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_PRESENCE_IMPLEMENTATION_CREDENTIAL_MANAGER_IMPL_H_
|
||||
#define THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_CREDENTIAL_MANAGER_IMPL_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/status/statusor.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/credential_storage.h"
|
||||
#include "third_party/nearby/presence/credential.h"
|
||||
#include "third_party/nearby/presence/implementation/credential_manager.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
|
||||
class CredentialManagerImpl : public CredentialManager {
|
||||
public:
|
||||
CredentialManagerImpl() = default;
|
||||
|
||||
void GenerateCredentials(
|
||||
proto::DeviceMetadata device_metadata, std::vector<TrustType> trust_types,
|
||||
GenerateCredentialsCallback credentials_generated_cb) override {}
|
||||
|
||||
void UpdateRemotePublicCredentials(
|
||||
std::string account_name,
|
||||
std::vector<PublicCredential> remote_public_creds,
|
||||
UpdateRemotePublicCredentialsCallback credentials_updated_cb) override{};
|
||||
|
||||
void GetPrivateCredentials(
|
||||
location::nearby::api::CredentialSelector credential_selector,
|
||||
location::nearby::api::GetPrivateCredentialCallback callback) override {}
|
||||
|
||||
// Used to fetch remote public creds when scanning.
|
||||
void GetPublicCredentials(
|
||||
location::nearby::api::CredentialSelector credential_selector,
|
||||
location::nearby::api::GetPublicCredentialCallback callback) override {}
|
||||
|
||||
absl::StatusOr<std::string> DecryptDataElements(
|
||||
absl::string_view metadata_key, absl::string_view salt,
|
||||
absl::string_view data_elements) override {
|
||||
return absl::UnimplementedError("DecryptDataElements unimplemented");
|
||||
}
|
||||
|
||||
private:
|
||||
location::nearby::CredentialStorage*
|
||||
credential_storage_; // NOLINT: further impl will use it.
|
||||
};
|
||||
|
||||
} // namespace presence
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_CREDENTIAL_MANAGER_IMPL_H_
|
||||
@@ -15,7 +15,7 @@
|
||||
#ifndef THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_SERVICE_CONTROLLER_IMPL_H_
|
||||
#define THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_SERVICE_CONTROLLER_IMPL_H_
|
||||
|
||||
#include "third_party/nearby/presence/implementation/credential_manager.h"
|
||||
#include "third_party/nearby/presence/implementation/credential_manager_impl.h"
|
||||
#include "third_party/nearby/presence/implementation/mediums/mediums.h"
|
||||
#include "third_party/nearby/presence/implementation/service_controller.h"
|
||||
|
||||
@@ -27,13 +27,10 @@ namespace nearby {
|
||||
namespace presence {
|
||||
|
||||
class ServiceControllerImpl : public ServiceController {
|
||||
public:
|
||||
ServiceControllerImpl() = default;
|
||||
~ServiceControllerImpl() override = default;
|
||||
|
||||
private:
|
||||
Mediums mediums_; // NOLINT: further impl will use it.
|
||||
CredentialManager credential_manager_; // NOLINT: further impl will use it.
|
||||
CredentialManagerImpl
|
||||
credential_manager_; // NOLINT: further impl will use it.
|
||||
};
|
||||
|
||||
} // namespace presence
|
||||
|
||||
Reference in New Issue
Block a user