Skip to content

Commit 41b4af6

Browse files
authored
Merge pull request #186 from eclipse-impl/swp-260766
Refactorings needed for injection support
2 parents 956c02c + 7d98047 commit 41b4af6

21 files changed

Lines changed: 151 additions & 131 deletions

score/hash/BUILD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ cc_library(
2424
name = "hash",
2525
features = COMPILER_WARNING_FEATURES,
2626
visibility = [
27-
"//visibility:public", # platform_only
27+
"//visibility:public",
2828
],
2929
deps = [
3030
"@score_baselibs//score/hash/code/core/factory/impl:crc_variant",
@@ -35,7 +35,7 @@ cc_library(
3535
name = "safe_hash",
3636
features = COMPILER_WARNING_FEATURES,
3737
tags = ["FFI"],
38-
visibility = ["//visibility:public"], # platform_only
38+
visibility = ["//visibility:public"],
3939
deps = [
4040
"@score_baselibs//score/hash/code/core/factory/impl:safe_crc_variant",
4141
],
@@ -45,7 +45,7 @@ cc_library(
4545
name = "hash_mock",
4646
testonly = True,
4747
features = COMPILER_WARNING_FEATURES,
48-
visibility = ["//visibility:public"], # platform_only
48+
visibility = ["//visibility:public"],
4949
deps = [
5050
"@score_baselibs//score/hash/code/core:hash_cal_mock",
5151
"@score_baselibs//score/hash/code/core/factory:factory_mock",
@@ -60,5 +60,5 @@ cc_unit_test_suites_for_host_and_qnx(
6060
"@score_baselibs//score/hash/code/crc:unit_tests",
6161
"@score_baselibs//score/hash/code/openssl:unit_tests",
6262
],
63-
visibility = ["//visibility:public"], # platform_only
63+
visibility = ["//visibility:public"],
6464
)

score/hash/code/common/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ cc_test(
7878
cc_unit_test_suites_for_host_and_qnx(
7979
name = "unit_tests",
8080
cc_unit_tests = [":unit_test"],
81-
visibility = ["//visibility:public"], # platform_only
81+
visibility = ["//visibility:public"],
8282
)

score/hash/code/common/algorithms.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ score::cpp::optional<std::uint8_t> HashSizeInBytes(const HashAlgorithm algorithm
2727
case HashAlgorithm::kCrc32:
2828
hashSizeInBytes = kCrc32Size;
2929
break;
30-
case HashAlgorithm::kCrc32Unused:
31-
hashSizeInBytes = kCrc32UnusedSize;
30+
case HashAlgorithm::kCrc32Autosar:
31+
hashSizeInBytes = kCrc32AutosarSize;
3232
break;
3333
case HashAlgorithm::kSha1:
3434
hashSizeInBytes = kSha1Size;
@@ -71,7 +71,7 @@ HashAlgorithm IdentifyHash(std::string_view hash_string) noexcept
7171
switch (hash_string.length())
7272
{
7373
case kCrc32Size * 2U:
74-
// there's no way to distinguish between kCrc32 and kCrc32Unused based on the bytes alone
74+
// there's no way to distinguish between kCrc32 and kCrc32Autosar based on the bytes alone
7575
identifiedHash = HashAlgorithm::kCrc32;
7676
break;
7777
case kSha1Size * 2U:
@@ -100,7 +100,7 @@ HashAlgorithm IdentifyHash(std::size_t hash_size_in_bytes) noexcept
100100
switch (hash_size_in_bytes)
101101
{
102102
case kCrc32Size:
103-
// there's no way to distinguish between kCrc32 and kCrc32Unused based on the bytes alone
103+
// there's no way to distinguish between kCrc32 and kCrc32Autosar based on the bytes alone
104104
identifiedHash = HashAlgorithm::kCrc32;
105105
break;
106106
case kSha1Size:

score/hash/code/common/algorithms.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ constexpr std::uint8_t kSha256Size{32U};
3636
constexpr std::uint8_t kSha384Size{48U};
3737
constexpr std::uint8_t kSha512Size{64U};
3838
constexpr std::uint8_t kCrc32Size{4U};
39-
constexpr std::uint8_t kCrc32UnusedSize{4U};
39+
constexpr std::uint8_t kCrc32AutosarSize{4U};
4040

4141
/// Cryptographic hash algorithm
4242
/* KW_SUPPRESS_START:UNUSED.STYLE.SINGLE_STMT_PER_LINE:this is a declaration of an enum; putting this on a single */
@@ -49,7 +49,7 @@ enum class HashAlgorithm : std::uint8_t
4949
kSha384,
5050
kSha512,
5151
kCrc32,
52-
kCrc32Unused,
52+
kCrc32Autosar,
5353
kLast
5454
};
5555

@@ -67,8 +67,8 @@ inline score::mw::log::LogStream& operator<<(score::mw::log::LogStream& stream,
6767
case HashAlgorithm::kCrc32:
6868
modifiedStream << "Crc32";
6969
break;
70-
case HashAlgorithm::kCrc32Unused:
71-
modifiedStream << "Crc32Unused";
70+
case HashAlgorithm::kCrc32Autosar:
71+
modifiedStream << "Crc32Autosar";
7272
break;
7373
case HashAlgorithm::kSha1:
7474
modifiedStream << "Sha1";

score/hash/code/common/algorithms_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ TEST(HashIdentify, CorrectSizes)
124124
{
125125
const auto expected_sizes_bytes = std::map<const HashAlgorithm, const std::uint8_t>{
126126
{HashAlgorithm::kCrc32, 4},
127-
{HashAlgorithm::kCrc32Unused, 4},
127+
{HashAlgorithm::kCrc32Autosar, 4},
128128
{HashAlgorithm::kSha1, 20},
129129
{HashAlgorithm::kSha256, 32},
130130
{HashAlgorithm::kSha384, 48},
@@ -154,8 +154,8 @@ TEST_F(AlgorithmLoggerFixture, CanLogAlgorithms)
154154
EXPECT_CALL(recorder_, LogStringView(_, {"CRC32:"}));
155155
EXPECT_CALL(recorder_, LogStringView(_, {"Crc32"}));
156156

157-
EXPECT_CALL(recorder_, LogStringView(_, {"CRC32 UNUSED:"}));
158-
EXPECT_CALL(recorder_, LogStringView(_, {"Crc32Unused"}));
157+
EXPECT_CALL(recorder_, LogStringView(_, {"CRC32 AUTOSAR:"}));
158+
EXPECT_CALL(recorder_, LogStringView(_, {"Crc32Autosar"}));
159159

160160
EXPECT_CALL(recorder_, LogStringView(_, {"SHA-1:"}));
161161
EXPECT_CALL(recorder_, LogStringView(_, {"Sha1"}));
@@ -181,7 +181,7 @@ TEST_F(AlgorithmLoggerFixture, CanLogAlgorithms)
181181
EXPECT_CALL(recorder_, LogStringView(_, {"}"}));
182182

183183
mw::log::LogInfo() << "CRC32:" << HashAlgorithm::kCrc32;
184-
mw::log::LogInfo() << "CRC32 UNUSED:" << HashAlgorithm::kCrc32Unused;
184+
mw::log::LogInfo() << "CRC32 AUTOSAR:" << HashAlgorithm::kCrc32Autosar;
185185
mw::log::LogInfo() << "SHA-1:" << HashAlgorithm::kSha1;
186186
mw::log::LogInfo() << "SHA-256:" << HashAlgorithm::kSha256;
187187
mw::log::LogInfo() << "SHA-384:" << HashAlgorithm::kSha384;

score/hash/code/core/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ cc_library(
5050
"hash_calculator_mock.h",
5151
],
5252
features = COMPILER_WARNING_FEATURES,
53-
visibility = ["@score_baselibs//score/hash:__subpackages__"],
53+
visibility = ["//visibility:public"],
5454
deps = [
5555
"@score_baselibs//score/hash/code/common",
5656
],
@@ -81,5 +81,5 @@ cc_unit_test_suites_for_host_and_qnx(
8181
test_suites_from_sub_packages = [
8282
"@score_baselibs//score/hash/code/core/factory/impl:unit_tests",
8383
],
84-
visibility = ["//visibility:public"], # platform_only
84+
visibility = ["//visibility:public"],
8585
)

score/hash/code/core/factory/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cc_library(
4444
"hash_calculator_factory_mock.h",
4545
],
4646
features = COMPILER_WARNING_FEATURES,
47-
visibility = ["@score_baselibs//score/hash:__subpackages__"],
47+
visibility = ["//visibility:public"],
4848
deps = [
4949
":factory",
5050
],

score/hash/code/core/factory/impl/BUILD

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,26 @@
1313

1414
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
1515
load("@score_baselibs//:bazel/unit_tests.bzl", "cc_unit_test_suites_for_host_and_qnx")
16-
load(":custom.bzl", "load_custom_targets", "load_custom_test_suites")
1716

1817
COMPILER_WARNING_FEATURES = [
1918
"treat_warnings_as_errors",
2019
"strict_warnings",
2120
"additional_warnings",
2221
]
2322

23+
cc_library(
24+
name = "factory_headers",
25+
hdrs = [
26+
"hash_calculator_factory.h",
27+
"safe_hash_calculator_factory.h",
28+
],
29+
visibility = ["//visibility:public"],
30+
deps = [
31+
"@score_baselibs//score/hash/code/core/factory",
32+
"@score_baselibs//score/hash/code/openssl:openssl_cal",
33+
],
34+
)
35+
2436
cc_library(
2537
name = "hash_impl_ieee",
2638
srcs = [
@@ -57,8 +69,13 @@ cc_library(
5769
],
5870
)
5971

60-
# Other options:
61-
# "@score_baselibs//score/hash/code/core/factory/impl:hash_impl_autosar"
72+
# Extension point:
73+
# `crc_variant` and `safe_crc_variant` are provided as extension points,
74+
# meaning that one may replace them with custom implementations that
75+
# provide different polynomials. To do so, define alternate `cc_library`
76+
# targets that reuse the generic CRC implementation pattern from
77+
# `//score/hash/code/crc:crc_ieee`, provide the desired polynomial
78+
# configuration, and override these two targets in `.bazelrc`.
6279
label_flag(
6380
name = "crc_variant",
6481
build_setting_default = ":hash_impl_ieee",
@@ -67,8 +84,6 @@ label_flag(
6784
],
6885
)
6986

70-
# Other options:
71-
# "@score_baselibs//score/hash/code/core/factory/impl:safe_hash_impl_autosar"
7287
label_flag(
7388
name = "safe_crc_variant",
7489
build_setting_default = ":safe_hash_impl_ieee",
@@ -96,8 +111,6 @@ cc_test(
96111

97112
cc_unit_test_suites_for_host_and_qnx(
98113
name = "unit_tests",
99-
cc_unit_tests = [":unit_test"] + load_custom_test_suites(),
100-
visibility = ["//visibility:public"], # platform_only
114+
cc_unit_tests = [":unit_test"],
115+
visibility = ["//visibility:public"],
101116
)
102-
103-
load_custom_targets()

score/hash/code/core/factory/impl/custom.bzl

Lines changed: 0 additions & 20 deletions
This file was deleted.

score/hash/code/core/factory/impl/hash_calculator_factory_ieee.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Result<std::unique_ptr<IHashCalculator>> HashCalculatorFactory::CreateHashCalcul
6161
std::make_unique<OpensslHashCalculator>(std::move(*digest)));
6262
break;
6363
}
64-
case HashAlgorithm::kCrc32Unused:
64+
case HashAlgorithm::kCrc32Autosar:
6565
case HashAlgorithm::kNone:
6666
case HashAlgorithm::kLast:
6767
default:

0 commit comments

Comments
 (0)