Add platform agnostic implementation of Credential_Storage class.

PiperOrigin-RevId: 468251604
This commit is contained in:
Anthony Rueda
2022-08-17 11:36:58 -07:00
committed by Copybara-Service
parent b57d03425f
commit 4d2ff863f9
4 changed files with 111 additions and 19 deletions
+3
View File
@@ -518,6 +518,9 @@ let package = Package(
"connections/implementation/mediums/webrtc",
// This breaks the build, but seems to work fine without it?
"internal/platform/medium_environment.cc",
// This file breaks the build:
// TODO: compile the proto and upload it to github. Then remove this file from exclude list.
"internal/platform/credential_storage.cc",
],
sources: [
"compiled_proto",
+56
View File
@@ -0,0 +1,56 @@
// 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.
#include "internal/platform/credential_storage.h"
namespace location {
namespace nearby {
using ::nearby::internal::PrivateCredential;
using ::nearby::internal::PublicCredential;
void CredentialStorage::SavePrivateCredentials(
std::string manager_app_id, absl::string_view account_name,
const std::vector<PrivateCredential>& private_credentials,
api::SaveCredentialsResultCallback callback) {
return impl_->SavePrivateCredentials(manager_app_id, account_name,
private_credentials, callback);
}
void CredentialStorage::SavePublicCredentials(
std::string manager_app_id, absl::string_view account_name,
const std::vector<PublicCredential>& public_credentials,
api::PublicCredentialType public_credential_type,
api::SaveCredentialsResultCallback callback) {
return impl_->SavePublicCredentials(manager_app_id, account_name,
public_credentials,
public_credential_type, callback);
}
void CredentialStorage::GetPrivateCredentials(
const api::CredentialSelector& credential_selector,
api::GetPrivateCredentialsResultCallback callback) {
return impl_->GetPrivateCredentials(credential_selector, callback);
}
void CredentialStorage::GetPublicCredentials(
const api::CredentialSelector& credential_selector,
api::PublicCredentialType public_credential_type,
api::GetPublicCredentialsResultCallback callback) {
return impl_->GetPublicCredentials(credential_selector,
public_credential_type, callback);
}
} // namespace nearby
} // namespace location
+34 -2
View File
@@ -15,22 +15,54 @@
#ifndef THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_CREDENTIAL_STORAGE_H_
#define THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_CREDENTIAL_STORAGE_H_
#include <memory>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "internal/platform/implementation/credential_storage.h"
namespace location {
namespace nearby {
/*
* The instance of CredentialStorage is owned by {@code CredentialManager}.
* It's a wrapper on top of implementation/credential_storage.h to providing
* credential storage operations for Nearby logic layer to invoke.
*/
class CredentialStorage {
class CredentialStorage final {
public:
CredentialStorage() = default;
~CredentialStorage() = default;
// CredentialStorage class is movable but not copyable.
CredentialStorage(CredentialStorage&& other) = default;
CredentialStorage& operator=(CredentialStorage&& other) = default;
void SavePrivateCredentials(
std::string manager_app_id, absl::string_view account_name,
const std::vector<::nearby::internal::PrivateCredential>&
private_credentials,
api::SaveCredentialsResultCallback callback);
void SavePublicCredentials(
std::string manager_app_id, absl::string_view account_name,
const std::vector<::nearby::internal::PublicCredential>&
public_credentials,
api::PublicCredentialType public_credential_type,
api::SaveCredentialsResultCallback callback);
// Used to fetch private creds when broadcasting.
void GetPrivateCredentials(const api::CredentialSelector& credential_selector,
api::GetPrivateCredentialsResultCallback callback);
// Used to fetch remote public creds when scanning.
void GetPublicCredentials(const api::CredentialSelector& credential_selector,
api::PublicCredentialType public_credential_type,
api::GetPublicCredentialsResultCallback callback);
private:
api::CredentialStorage credential_storage_;
std::unique_ptr<api::CredentialStorage> impl_;
};
} // namespace nearby
@@ -20,6 +20,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "internal/platform/exception.h"
#include "internal/proto/credential.pb.h"
@@ -27,10 +28,6 @@ namespace location {
namespace nearby {
namespace api {
using ::nearby::internal::IdentityType;
using ::nearby::internal::PrivateCredential;
using ::nearby::internal::PublicCredential;
enum class CredentialOperationStatus {
kUnknown = 0,
kFailed = 1,
@@ -40,7 +37,7 @@ enum class CredentialOperationStatus {
struct CredentialSelector {
std::string manager_app_id;
std::string account_name;
IdentityType identity_type;
::nearby::internal::IdentityType identity_type;
};
enum PublicCredentialType {
@@ -53,12 +50,14 @@ struct SaveCredentialsResultCallback {
};
struct GetPrivateCredentialsResultCallback {
std::function<void(std::vector<PrivateCredential>)> credentials_fetched_cb;
std::function<void(std::vector<::nearby::internal::PrivateCredential>)>
credentials_fetched_cb;
std::function<void(CredentialOperationStatus)> get_credentials_failed_cb;
};
struct GetPublicCredentialsResultCallback {
std::function<void(std::vector<PublicCredential>)> credentials_fetched_cb;
std::function<void(std::vector<::nearby::internal::PublicCredential>)>
credentials_fetched_cb;
std::function<void(CredentialOperationStatus)> get_credentials_failed_cb;
};
@@ -75,26 +74,28 @@ class CredentialStorage {
// Skip the save/update if the provided vector is empty.
// Another way is to break this into two APIs for save and update separately.
virtual void SavePrivateCredentials(
std::string manager_app_id, std::string account_name,
std::vector<PrivateCredential> private_credentials,
SaveCredentialsResultCallback callback);
std::string manager_app_id, absl::string_view account_name,
const std::vector<::nearby::internal::PrivateCredential>&
private_credentials,
SaveCredentialsResultCallback callback) = 0;
virtual void SavePublicCredentials(
std::string manager_app_id, std::string account_name,
std::vector<PublicCredential> public_credentials,
std::string manager_app_id, absl::string_view account_name,
const std::vector<::nearby::internal::PublicCredential>&
public_credentials,
PublicCredentialType public_credential_type,
SaveCredentialsResultCallback callback);
SaveCredentialsResultCallback callback) = 0;
// Used to fetch private creds when broadcasting.
virtual void GetPrivateCredentials(
CredentialSelector credential_selector,
GetPrivateCredentialsResultCallback callback);
const CredentialSelector& credential_selector,
GetPrivateCredentialsResultCallback callback) = 0;
// Used to fetch remote public creds when scanning.
virtual void GetPublicCredentials(
CredentialSelector credential_selector,
const CredentialSelector& credential_selector,
PublicCredentialType public_credential_type,
GetPublicCredentialsResultCallback callback);
GetPublicCredentialsResultCallback callback) = 0;
};
} // namespace api