diff --git a/Package.swift b/Package.swift index 6c131ffd..d76b188a 100644 --- a/Package.swift +++ b/Package.swift @@ -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", diff --git a/internal/platform/credential_storage.cc b/internal/platform/credential_storage.cc new file mode 100644 index 00000000..e4734103 --- /dev/null +++ b/internal/platform/credential_storage.cc @@ -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& 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& 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 diff --git a/internal/platform/credential_storage.h b/internal/platform/credential_storage.h index 4142fb51..4c0ef0f9 100644 --- a/internal/platform/credential_storage.h +++ b/internal/platform/credential_storage.h @@ -15,22 +15,54 @@ #ifndef THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_CREDENTIAL_STORAGE_H_ #define THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_CREDENTIAL_STORAGE_H_ +#include +#include +#include + +#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 impl_; }; } // namespace nearby diff --git a/internal/platform/implementation/credential_storage.h b/internal/platform/implementation/credential_storage.h index d0cc9999..0d39c0e4 100644 --- a/internal/platform/implementation/credential_storage.h +++ b/internal/platform/implementation/credential_storage.h @@ -20,6 +20,7 @@ #include #include +#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)> credentials_fetched_cb; + std::function)> + credentials_fetched_cb; std::function get_credentials_failed_cb; }; struct GetPublicCredentialsResultCallback { - std::function)> credentials_fetched_cb; + std::function)> + credentials_fetched_cb; std::function 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 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 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