From 8446944697ea4872af5adfb416fd6d2f5c69c396 Mon Sep 17 00:00:00 2001 From: Janusz Sobczak Date: Thu, 11 Aug 2022 10:36:17 -0700 Subject: [PATCH] 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 --- presence/BUILD | 81 ------------------- presence/implementation/BUILD | 54 +++++++++++-- .../{ => implementation}/action_factory.cc | 2 +- .../{ => implementation}/action_factory.h | 8 +- .../action_factory_test.cc | 4 +- .../implementation/advertisement_decoder.cc | 2 +- .../implementation/advertisement_factory.cc | 9 ++- .../implementation/advertisement_factory.h | 6 +- .../advertisement_factory_test.cc | 22 ++--- .../base_broadcast_request.cc} | 12 +-- .../base_broadcast_request.h} | 10 +-- .../base_broadcast_request_test.cc} | 8 +- .../implementation/credential_manager_impl.cc | 2 +- .../credential_manager_impl_test.cc | 2 +- presence/{ => implementation}/encryption.cc | 2 +- presence/{ => implementation}/encryption.h | 6 +- .../{ => implementation}/encryption_test.cc | 2 +- 17 files changed, 98 insertions(+), 134 deletions(-) rename presence/{ => implementation}/action_factory.cc (98%) rename presence/{ => implementation}/action_factory.h (83%) rename presence/{ => implementation}/action_factory_test.cc (96%) rename presence/{broadcast_request.cc => implementation/base_broadcast_request.cc} (81%) rename presence/{broadcast_request.h => implementation/base_broadcast_request.h} (87%) rename presence/{broadcast_request_test.cc => implementation/base_broadcast_request_test.cc} (84%) rename presence/{ => implementation}/encryption.cc (98%) rename presence/{ => implementation}/encryption.h (93%) rename presence/{ => implementation}/encryption_test.cc (98%) diff --git a/presence/BUILD b/presence/BUILD index 205d8878..5f0eb2fa 100644 --- a/presence/BUILD +++ b/presence/BUILD @@ -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", diff --git a/presence/implementation/BUILD b/presence/implementation/BUILD index 7785e780..8d56f2f6 100644 --- a/presence/implementation/BUILD +++ b/presence/implementation/BUILD @@ -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", ], diff --git a/presence/action_factory.cc b/presence/implementation/action_factory.cc similarity index 98% rename from presence/action_factory.cc rename to presence/implementation/action_factory.cc index 8667d3b8..f87d6b02 100644 --- a/presence/action_factory.cc +++ b/presence/implementation/action_factory.cc @@ -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 #include diff --git a/presence/action_factory.h b/presence/implementation/action_factory.h similarity index 83% rename from presence/action_factory.h rename to presence/implementation/action_factory.h index 8e162387..b2a43880 100644 --- a/presence/action_factory.h +++ b/presence/implementation/action_factory.h @@ -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 -#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_ diff --git a/presence/action_factory_test.cc b/presence/implementation/action_factory_test.cc similarity index 96% rename from presence/action_factory_test.cc rename to presence/implementation/action_factory_test.cc index 3204162e..34826b91 100644 --- a/presence/action_factory_test.cc +++ b/presence/implementation/action_factory_test.cc @@ -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 #include @@ -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 { diff --git a/presence/implementation/advertisement_decoder.cc b/presence/implementation/advertisement_decoder.cc index f276d6e2..b4ade393 100644 --- a/presence/implementation/advertisement_decoder.cc +++ b/presence/implementation/advertisement_decoder.cc @@ -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 { diff --git a/presence/implementation/advertisement_factory.cc b/presence/implementation/advertisement_factory.cc index 514a270c..d2aac054 100644 --- a/presence/implementation/advertisement_factory.cc +++ b/presence/implementation/advertisement_factory.cc @@ -71,9 +71,10 @@ uint8_t GetIdentityFieldType(PresenceIdentity::IdentityType type) { } absl::StatusOr AdvertisementFactory::CreateAdvertisement( - const BroadcastRequest& request) const { + const BaseBroadcastRequest& request) const { BleAdvertisementData advert = {}; - if (std::holds_alternative(request.variant)) { + if (std::holds_alternative( + request.variant)) { return CreateBaseNpAdvertisement(request); } return advert; @@ -81,9 +82,9 @@ absl::StatusOr AdvertisementFactory::CreateAdvertisement( absl::StatusOr AdvertisementFactory::CreateBaseNpAdvertisement( - const BroadcastRequest& request) const { + const BaseBroadcastRequest& request) const { const auto& presence = - std::get(request.variant); + std::get(request.variant); BleAdvertisementData advert{}; std::string payload; payload.push_back(kBaseVersion); diff --git a/presence/implementation/advertisement_factory.h b/presence/implementation/advertisement_factory.h index 3f44d395..43922c4f 100644 --- a/presence/implementation/advertisement_factory.h +++ b/presence/implementation/advertisement_factory.h @@ -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 CreateAdvertisement( - const BroadcastRequest& request) const; + const BaseBroadcastRequest& request) const; private: absl::StatusOr CreateBaseNpAdvertisement( - const BroadcastRequest& request) const; + const BaseBroadcastRequest& request) const; CredentialManager& credential_manager_; }; diff --git a/presence/implementation/advertisement_factory_test.cc b/presence/implementation/advertisement_factory_test.cc index ac49976b..1e142f3a 100644 --- a/presence/implementation/advertisement_factory_test.cc +++ b/presence/implementation/advertisement_factory_test.cc @@ -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"))); diff --git a/presence/broadcast_request.cc b/presence/implementation/base_broadcast_request.cc similarity index 81% rename from presence/broadcast_request.cc rename to presence/implementation/base_broadcast_request.cc index d6949aad..2f82cafa 100644 --- a/presence/broadcast_request.cc +++ b/presence/implementation/base_broadcast_request.cc @@ -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_ diff --git a/presence/broadcast_request.h b/presence/implementation/base_broadcast_request.h similarity index 87% rename from presence/broadcast_request.h rename to presence/implementation/base_broadcast_request.h index d6c91907..a08c1466 100644 --- a/presence/broadcast_request.h +++ b/presence/implementation/base_broadcast_request.h @@ -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 @@ -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_ diff --git a/presence/broadcast_request_test.cc b/presence/implementation/base_broadcast_request_test.cc similarity index 84% rename from presence/broadcast_request_test.cc rename to presence/implementation/base_broadcast_request_test.cc index 0799a0fb..38b0791d 100644 --- a/presence/broadcast_request_test.cc +++ b/presence/implementation/base_broadcast_request_test.cc @@ -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 @@ -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(request.variant)); + EXPECT_TRUE(std::holds_alternative( + request.variant)); EXPECT_EQ(request.salt.size(), 2); EXPECT_EQ(request.tx_power, kTxPower); } diff --git a/presence/implementation/credential_manager_impl.cc b/presence/implementation/credential_manager_impl.cc index 23a4806b..36250d13 100644 --- a/presence/implementation/credential_manager_impl.cc +++ b/presence/implementation/credential_manager_impl.cc @@ -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 { diff --git a/presence/implementation/credential_manager_impl_test.cc b/presence/implementation/credential_manager_impl_test.cc index 759742f7..d3c48fc6 100644 --- a/presence/implementation/credential_manager_impl_test.cc +++ b/presence/implementation/credential_manager_impl_test.cc @@ -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 { diff --git a/presence/encryption.cc b/presence/implementation/encryption.cc similarity index 98% rename from presence/encryption.cc rename to presence/implementation/encryption.cc index 1a3a1f9e..51381d7c 100644 --- a/presence/encryption.cc +++ b/presence/implementation/encryption.cc @@ -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 #include diff --git a/presence/encryption.h b/presence/implementation/encryption.h similarity index 93% rename from presence/encryption.h rename to presence/implementation/encryption.h index 7d745216..cd8e9cc8 100644 --- a/presence/encryption.h +++ b/presence/implementation/encryption.h @@ -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 @@ -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_ diff --git a/presence/encryption_test.cc b/presence/implementation/encryption_test.cc similarity index 98% rename from presence/encryption_test.cc rename to presence/implementation/encryption_test.cc index 1897610a..f66b39bb 100644 --- a/presence/encryption_test.cc +++ b/presence/implementation/encryption_test.cc @@ -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