Hide internal code in implementation/

Refactoring change.

action_factory* -> implementation/action_factory*
broadcast_request* -> implementation/base_broadcast_request*
encryption* -> implementation/encryption*

Clean up build targets.

PiperOrigin-RevId: 466992367
This commit is contained in:
Janusz Sobczak
2022-08-11 10:37:56 -07:00
committed by Copybara-Service
parent 76d45f20db
commit 8446944697
17 changed files with 98 additions and 134 deletions
-81
View File
@@ -67,46 +67,6 @@ cc_library(
],
)
cc_library(
name = "broadcast_request",
srcs = ["broadcast_request.cc"],
hdrs = ["broadcast_request.h"],
deps = [
":credential",
":encryption",
"//internal/platform:logging",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:variant",
],
)
cc_library(
name = "encryption",
srcs = ["encryption.cc"],
hdrs = ["encryption.h"],
deps = [
"//internal/platform:logging",
"//third_party/tink/cc/subtle",
"@boringssl//:crypto",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
],
)
cc_library(
name = "action_factory",
srcs = ["action_factory.cc"],
hdrs = ["action_factory.h"],
deps = [
":broadcast_request",
":types",
"//internal/platform:logging",
"@com_google_absl//absl/types:optional",
],
)
cc_library(
name = "credential",
srcs = ["presence_identity.cc"],
@@ -118,47 +78,6 @@ cc_library(
],
)
cc_test(
name = "broadcast_request_test",
size = "small",
srcs = ["broadcast_request_test.cc"],
deps = [
":broadcast_request",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/types:variant",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "encryption_test",
size = "small",
srcs = ["encryption_test.cc"],
deps = [
":encryption",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "action_factory_test",
size = "small",
srcs = ["action_factory_test.cc"],
deps = [
":action_factory",
":broadcast_request",
":types",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "types_test",
size = "small",
+49 -5
View File
@@ -16,16 +16,22 @@ licenses(["notice"])
cc_library(
name = "internal",
srcs = [
"action_factory.cc",
"advertisement_decoder.cc",
"advertisement_factory.cc",
"base_broadcast_request.cc",
"credential_manager_impl.cc",
"encryption.cc",
],
hdrs = [
"action_factory.h",
"advertisement_decoder.h",
"advertisement_factory.h",
"base_broadcast_request.h",
"broadcast_manager.h",
"credential_manager.h",
"credential_manager_impl.h",
"encryption.h",
"mock_service_controller.h",
"scan_manager.h",
"service_controller.h",
@@ -42,17 +48,18 @@ cc_library(
"//internal/platform:uuid",
"//internal/platform/implementation:comm",
"//internal/platform/implementation:types",
"//presence:action_factory",
"//presence:broadcast_request",
"//presence:credential",
"//presence:encryption",
"//presence:types",
"//presence/implementation/mediums",
"//presence/proto:credential_cc_proto",
"//third_party/tink/cc/subtle",
"@boringssl//:crypto",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/types:optional",
"@com_google_absl//absl/types:variant",
],
)
@@ -77,7 +84,6 @@ cc_test(
deps = [
":internal",
"//internal/platform/implementation/g3", # build_cleaner: keep
"//presence:action_factory",
"//presence:types",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/status",
@@ -86,6 +92,45 @@ cc_test(
],
)
cc_test(
name = "encryption_test",
size = "small",
srcs = ["encryption_test.cc"],
deps = [
":internal",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "base_broadcast_request_test",
srcs = ["base_broadcast_request_test.cc"],
deps = [
":internal",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/types:variant",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "action_factory_test",
size = "small",
srcs = ["action_factory_test.cc"],
deps = [
":internal",
"//internal/platform/implementation/g3", # build_cleaner: keep
"//presence:types",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "credential_manager_impl_test",
size = "small",
@@ -96,7 +141,6 @@ cc_test(
"//internal/crypto",
"//internal/platform/implementation:types",
"//internal/platform/implementation/g3", # build_cleaner: keep
"//presence:encryption",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "presence/action_factory.h"
#include "presence/implementation/action_factory.h"
#include <algorithm>
#include <vector>
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_PRESENCE_ACTION_FACTORY_H_
#define THIRD_PARTY_NEARBY_PRESENCE_ACTION_FACTORY_H_
#ifndef THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_ACTION_FACTORY_H_
#define THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_ACTION_FACTORY_H_
#include <vector>
#include "presence/broadcast_request.h"
#include "presence/data_element.h"
#include "presence/implementation/base_broadcast_request.h"
namespace nearby {
namespace presence {
@@ -42,4 +42,4 @@ class ActionFactory {
} // namespace presence
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_PRESENCE_ACTION_FACTORY_H_
#endif // THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_ACTION_FACTORY_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "presence/action_factory.h"
#include "presence/implementation/action_factory.h"
#include <string>
#include <vector>
@@ -21,8 +21,8 @@
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "absl/strings/escaping.h"
#include "presence/broadcast_request.h"
#include "presence/data_element.h"
#include "presence/implementation/base_broadcast_request.h"
namespace nearby {
namespace presence {
@@ -25,8 +25,8 @@
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "internal/platform/logging.h"
#include "presence/action_factory.h"
#include "presence/data_element.h"
#include "presence/implementation/action_factory.h"
namespace nearby {
namespace presence {
@@ -71,9 +71,10 @@ uint8_t GetIdentityFieldType(PresenceIdentity::IdentityType type) {
}
absl::StatusOr<BleAdvertisementData> AdvertisementFactory::CreateAdvertisement(
const BroadcastRequest& request) const {
const BaseBroadcastRequest& request) const {
BleAdvertisementData advert = {};
if (std::holds_alternative<BroadcastRequest::BasePresence>(request.variant)) {
if (std::holds_alternative<BaseBroadcastRequest::BasePresence>(
request.variant)) {
return CreateBaseNpAdvertisement(request);
}
return advert;
@@ -81,9 +82,9 @@ absl::StatusOr<BleAdvertisementData> AdvertisementFactory::CreateAdvertisement(
absl::StatusOr<BleAdvertisementData>
AdvertisementFactory::CreateBaseNpAdvertisement(
const BroadcastRequest& request) const {
const BaseBroadcastRequest& request) const {
const auto& presence =
std::get<BroadcastRequest::BasePresence>(request.variant);
std::get<BaseBroadcastRequest::BasePresence>(request.variant);
BleAdvertisementData advert{};
std::string payload;
payload.push_back(kBaseVersion);
@@ -20,7 +20,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "internal/platform/implementation/ble_v2.h"
#include "presence/broadcast_request.h"
#include "presence/implementation/base_broadcast_request.h"
#include "presence/implementation/credential_manager.h"
#include "presence/presence_identity.h"
@@ -38,11 +38,11 @@ class AdvertisementFactory {
/** Returns a BLE advertisement for given `request` */
absl::StatusOr<BleAdvertisementData> CreateAdvertisement(
const BroadcastRequest& request) const;
const BaseBroadcastRequest& request) const;
private:
absl::StatusOr<BleAdvertisementData> CreateBaseNpAdvertisement(
const BroadcastRequest& request) const;
const BaseBroadcastRequest& request) const;
CredentialManager& credential_manager_;
};
@@ -22,8 +22,8 @@
#include "gtest/gtest.h"
#include "absl/status/status.h"
#include "absl/strings/escaping.h"
#include "presence/action_factory.h"
#include "presence/data_element.h"
#include "presence/implementation/action_factory.h"
#include "presence/implementation/credential_manager_impl.h"
namespace nearby {
@@ -53,11 +53,11 @@ TEST(AdvertisementFactory, CreateAdvertisementFromPrivateIdentity) {
data_elements.emplace_back(DataElement::kActionFieldType,
action::kActiveUnlockAction);
Action action = ActionFactory::CreateAction(data_elements);
BroadcastRequest request =
BroadcastRequest(BasePresenceRequestBuilder(identity)
.SetSalt(salt)
.SetTxPower(5)
.SetAction(action));
BaseBroadcastRequest request =
BaseBroadcastRequest(BasePresenceRequestBuilder(identity)
.SetSalt(salt)
.SetTxPower(5)
.SetAction(action));
EXPECT_CALL(credential_manager, GetBaseEncryptedMetadataKey(identity))
.WillOnce(Return(absl::HexStringToBytes("1011121314151617181920212223")));
EXPECT_CALL(
@@ -87,11 +87,11 @@ TEST(AdvertisementFactory, CreateAdvertisementFailsWhenCredentialManagerFails) {
data_elements.emplace_back(DataElement::kActionFieldType,
action::kActiveUnlockAction);
Action action = ActionFactory::CreateAction(data_elements);
BroadcastRequest request =
BroadcastRequest(BasePresenceRequestBuilder(identity)
.SetSalt("AB")
.SetTxPower(5)
.SetAction(action));
BaseBroadcastRequest request =
BaseBroadcastRequest(BasePresenceRequestBuilder(identity)
.SetSalt("AB")
.SetTxPower(5)
.SetAction(action));
EXPECT_CALL(credential_manager, GetBaseEncryptedMetadataKey(identity))
.WillOnce(Return(absl::UnimplementedError(
"GetBaseEncryptedMetadataKey not implemented")));
@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "presence/broadcast_request.h"
#include "presence/implementation/base_broadcast_request.h"
#include "absl/strings/string_view.h"
#include "internal/platform/logging.h"
#include "presence/encryption.h"
#include "presence/implementation/encryption.h"
#include "presence/presence_identity.h"
namespace nearby {
@@ -44,10 +44,10 @@ BasePresenceRequestBuilder& BasePresenceRequestBuilder::SetAction(
return *this;
}
BasePresenceRequestBuilder::operator BroadcastRequest() const {
BroadcastRequest::BasePresence presence{.identity = identity_,
.action = action_};
BroadcastRequest broadcast_request{
BasePresenceRequestBuilder::operator BaseBroadcastRequest() const {
BaseBroadcastRequest::BasePresence presence{.identity = identity_,
.action = action_};
BaseBroadcastRequest broadcast_request{
.variant = presence,
.salt = salt_.size() == kSaltSize
? salt_
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_PRESENCE_BROADCAST_REQUEST_H_
#define THIRD_PARTY_NEARBY_PRESENCE_BROADCAST_REQUEST_H_
#ifndef THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_BASE_BROADCAST_REQUEST_H_
#define THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_BASE_BROADCAST_REQUEST_H_
#include <stdint.h>
@@ -35,7 +35,7 @@ struct Action {
};
/** Defines a Nearby Presence broadcast request */
struct BroadcastRequest {
struct BaseBroadcastRequest {
struct BasePresence {
PresenceIdentity identity;
Action action;
@@ -68,7 +68,7 @@ class BasePresenceRequestBuilder {
BasePresenceRequestBuilder& SetTxPower(int8_t tx_power);
BasePresenceRequestBuilder& SetAction(const Action& action);
explicit operator BroadcastRequest() const;
explicit operator BaseBroadcastRequest() const;
private:
PresenceIdentity identity_;
@@ -80,4 +80,4 @@ class BasePresenceRequestBuilder {
} // namespace presence
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_PRESENCE_BROADCAST_REQUEST_H_
#endif // THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_BASE_BROADCAST_REQUEST_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "presence/broadcast_request.h"
#include "presence/implementation/base_broadcast_request.h"
#include <variant>
@@ -29,11 +29,11 @@ TEST(BroadcastRequestTest, CreateBasePresenceRequest) {
PresenceIdentity identity;
constexpr int8_t kTxPower = -13;
BroadcastRequest request = BroadcastRequest(
BaseBroadcastRequest request = BaseBroadcastRequest(
BasePresenceRequestBuilder(identity).SetTxPower(kTxPower));
EXPECT_TRUE(
std::holds_alternative<BroadcastRequest::BasePresence>(request.variant));
EXPECT_TRUE(std::holds_alternative<BaseBroadcastRequest::BasePresence>(
request.variant));
EXPECT_EQ(request.salt.size(), 2);
EXPECT_EQ(request.tx_power, kTxPower);
}
@@ -25,7 +25,7 @@
#include "internal/platform/base64_utils.h"
#include "internal/platform/implementation/crypto.h"
#include "internal/platform/logging.h"
#include "presence/encryption.h"
#include "presence/implementation/encryption.h"
namespace nearby {
namespace presence {
@@ -23,7 +23,7 @@
#include "internal/crypto/aead.h"
#include "internal/crypto/hkdf.h"
#include "internal/platform/implementation/crypto.h"
#include "presence/encryption.h"
#include "presence/implementation/encryption.h"
namespace nearby {
namespace presence {
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "presence/encryption.h"
#include "presence/implementation/encryption.h"
#include <algorithm>
#include <cstring>
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_PRESENCE_ENCRYPTION_H_
#define THIRD_PARTY_NEARBY_PRESENCE_ENCRYPTION_H_
#ifndef THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_ENCRYPTION_H_
#define THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_ENCRYPTION_H_
#include <string>
@@ -71,4 +71,4 @@ class Encryption {
} // namespace presence
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_PRESENCE_ENCRYPTION_H_
#endif // THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_ENCRYPTION_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "presence/encryption.h"
#include "presence/implementation/encryption.h"
#include <string>