Skip to content

Commit 58311be

Browse files
Merge pull request #20 from IABTechLab/ant-UID2-1322-compile-warning-as-error
Treat compile warnings as errors
2 parents 40dfb82 + 64c5e9a commit 58311be

10 files changed

Lines changed: 48 additions & 44 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CMake Mac
1+
name: CMake macOS
22

33
on: [push]
44

@@ -14,7 +14,7 @@ jobs:
1414

1515
- name: Dev environment
1616
run: |
17-
${{github.workspace}}/tools/install-macosx-deps.sh
17+
${{github.workspace}}/tools/install-macos-deps.sh
1818
1919
- name: Build and Test
2020
run: ${{github.workspace}}/tools/build.sh ${{matrix.build_type}}-${{matrix.compiler}}

CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
cmake_minimum_required (VERSION 3.12)
1+
cmake_minimum_required(VERSION 3.12)
22

3-
project ("uid2-client" VERSION 3.0.1)
3+
project("uid2-client" VERSION 3.0.1)
44

55
configure_file(VERSION.in VERSION @ONLY)
66

7-
set (CMAKE_CXX_STANDARD 11)
7+
option(WARNING_AS_ERROR "Treat compiler warnings as errors" ON)
88

9-
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
9+
set(CMAKE_CXX_STANDARD 11)
10+
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb")
11+
add_compile_options(-Wall -Wextra)
12+
if(WARNING_AS_ERROR)
13+
add_compile_options(-Werror)
14+
endif()
15+
16+
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
1017
if (NOT DEFINED OPENSSL_ROOT_DIR)
1118
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)
1219
endif()

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ This SDK simplifies integration with UID2 for those using C++.
88

99
This SDK requires C++ version 11.
1010

11+
Supported platforms:
12+
13+
- Linux (tested on Ubuntu 22.04)
14+
- MacOS (tested on macOS 12 Monterey and macOS 13 Ventura)
15+
1116
Supported compilers:
1217

1318
- clang (tested on versions 12 and 14)
@@ -28,10 +33,10 @@ sudo ./tools/install-ubuntu-devtools.sh
2833
sudo ./tools/install-ubuntu-deps.sh
2934
```
3035

31-
To set up dependencies on Mac OS X, make sure you have latest xcode installed, then:
36+
To set up dependencies on macOS, make sure you have latest xcode installed, then:
3237

3338
```
34-
./tools/install-macosx-deps.sh
39+
./tools/install-macos-deps.sh
3540
```
3641

3742
If you want to have clang-14 installed on Mac, run these additional commands:
@@ -92,6 +97,12 @@ Most modern IDEs should pick that up automatically. To reformat all the code, ru
9297
./tools/devenv.sh ./tools/format.sh --fix
9398
```
9499

100+
By default, compiler warnings are treated as errors. To temporarily disable this behavior, set CMake `WARNING_AS_ERROR` option to `OFF`. For example:
101+
102+
```
103+
cmake -DWARNING_AS_ERROR=OFF
104+
```
105+
95106
Additionally the codebase is subject to clang-tidy checks. Some IDEs can pick that up automatically. Otherwise
96107
you can run the checks by running (requires docker):
97108

lib/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ add_library(uid2client
1919
${EXTERNAL_SOURCES}
2020
${CMAKE_CURRENT_BINARY_DIR}/version.h)
2121

22+
set_source_files_properties(${EXTERNAL_SOURCES} PROPERTIES COMPILE_FLAGS -Wno-error)
23+
2224
target_include_directories(uid2client SYSTEM
2325
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/external
2426
PRIVATE ${OPENSSL_INCLUDE_DIR})

lib/bigendianprocessor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class BigEndianByteReader {
7676
}
7777

7878
const std::uint8_t* bytes_;
79-
int position_;
8079
int size_;
80+
int position_;
8181
};
8282

8383
class BigEndianByteWriter {
@@ -140,7 +140,7 @@ class BigEndianByteWriter {
140140
}
141141

142142
std::uint8_t* bytes_;
143-
int position_;
144143
int size_;
144+
int position_;
145145
};
146146
} // namespace uid2

lib/uid2encryption.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static DecryptionResult DecryptTokenV2(const std::vector<std::uint8_t>& encrypte
123123
idString.resize(idLength);
124124
identityPayloadReader.ReadBytes(const_cast<std::uint8_t*>(reinterpret_cast<const std::uint8_t*>(idString.data())), 0, idLength);
125125

126-
const std::int32_t privacyBits = identityPayloadReader.ReadInt32(); // NOLINT(clang-analyzer-deadcode.DeadStores)
126+
/*const std::int32_t privacyBits = */ identityPayloadReader.ReadInt32();
127127
const Timestamp established = Timestamp::FromEpochMilli(identityPayloadReader.ReadInt64());
128128

129129
if (checkValidity && expires < now) {
@@ -143,7 +143,7 @@ DecryptTokenV3(const std::vector<std::uint8_t>& encryptedId, const KeyContainer&
143143
return DecryptionResult::MakeError(DecryptionStatus::INVALID_IDENTITY_SCOPE);
144144
}
145145

146-
const auto version = reader.ReadByte(); // NOLINT(clang-analyzer-deadcode.DeadStores)
146+
/*const auto version = */ reader.ReadByte();
147147

148148
const std::int32_t masterKeyId = reader.ReadInt32();
149149
const auto* const masterKey = keys.Get(masterKeyId);
@@ -152,20 +152,20 @@ DecryptTokenV3(const std::vector<std::uint8_t>& encryptedId, const KeyContainer&
152152
}
153153

154154
std::uint8_t masterPayload[256];
155-
if (reader.GetRemainingSize() > sizeof(masterPayload)) {
155+
if (reader.GetRemainingSize() > static_cast<int>(sizeof(masterPayload))) {
156156
return DecryptionResult::MakeError(DecryptionStatus::INVALID_PAYLOAD);
157157
}
158158
const int masterPayloadLen = DecryptGCM(reader.GetCurrentData(), reader.GetRemainingSize(), masterKey->secret_.data(), masterPayload);
159159

160160
BigEndianByteReader masterPayloadReader(masterPayload, masterPayloadLen);
161161

162162
const Timestamp expires = Timestamp::FromEpochMilli(masterPayloadReader.ReadInt64());
163-
const Timestamp created = Timestamp::FromEpochMilli(masterPayloadReader.ReadInt64()); // NOLINT(clang-analyzer-deadcode.DeadStores)
163+
/*const Timestamp created = */ Timestamp::FromEpochMilli(masterPayloadReader.ReadInt64());
164164

165-
const auto operatorSiteId = masterPayloadReader.ReadInt32(); // NOLINT(clang-analyzer-deadcode.DeadStores)
166-
const auto operatorType = masterPayloadReader.ReadByte(); // NOLINT(clang-analyzer-deadcode.DeadStores)
167-
const auto operatorVersion = masterPayloadReader.ReadInt32(); // NOLINT(clang-analyzer-deadcode.DeadStores)
168-
const auto operatorClientKeyId = masterPayloadReader.ReadInt32(); // NOLINT(clang-analyzer-deadcode.DeadStores)
165+
/*const auto operatorSiteId = */ masterPayloadReader.ReadInt32();
166+
/*const auto operatorType = */ masterPayloadReader.ReadByte();
167+
/*const auto operatorVersion = */ masterPayloadReader.ReadInt32();
168+
/*const auto operatorClientKeyId = */ masterPayloadReader.ReadInt32();
169169

170170
const auto siteKeyId = masterPayloadReader.ReadInt32();
171171
const auto* const siteKey = keys.Get(siteKeyId);
@@ -174,20 +174,20 @@ DecryptTokenV3(const std::vector<std::uint8_t>& encryptedId, const KeyContainer&
174174
}
175175

176176
std::uint8_t sitePayload[128];
177-
if (masterPayloadReader.GetRemainingSize() > sizeof(sitePayload)) {
177+
if (masterPayloadReader.GetRemainingSize() > static_cast<int>(sizeof(sitePayload))) {
178178
return DecryptionResult::MakeError(DecryptionStatus::INVALID_PAYLOAD);
179179
}
180180
const auto sitePayloadLen = DecryptGCM(masterPayloadReader.GetCurrentData(), masterPayloadReader.GetRemainingSize(), siteKey->secret_.data(), sitePayload);
181181

182182
BigEndianByteReader sitePayloadReader(sitePayload, sitePayloadLen);
183183

184184
const auto siteId = sitePayloadReader.ReadInt32();
185-
const auto publisherId = sitePayloadReader.ReadInt64(); // NOLINT(clang-analyzer-deadcode.DeadStores)
186-
const auto publisherKeyId = sitePayloadReader.ReadInt32(); // NOLINT(clang-analyzer-deadcode.DeadStores)
185+
/*const auto publisherId = */ sitePayloadReader.ReadInt64();
186+
/*const auto publisherKeyId = */ sitePayloadReader.ReadInt32();
187187

188-
const auto privacyBits = sitePayloadReader.ReadInt32(); // NOLINT(clang-analyzer-deadcode.DeadStores)
188+
/*const auto privacyBits = */ sitePayloadReader.ReadInt32();
189189
const Timestamp established = Timestamp::FromEpochMilli(sitePayloadReader.ReadInt64());
190-
const Timestamp refreshed = Timestamp::FromEpochMilli(sitePayloadReader.ReadInt64()); // NOLINT(clang-analyzer-deadcode.DeadStores)
190+
/*const Timestamp refreshed = */ Timestamp::FromEpochMilli(sitePayloadReader.ReadInt64());
191191

192192
if (checkValidity && expires < now) {
193193
return DecryptionResult::MakeError(DecryptionStatus::EXPIRED_TOKEN, established, siteId, siteKey->siteId_);
@@ -314,7 +314,7 @@ static DecryptionDataResult DecryptDataV2(const std::vector<std::uint8_t>& encry
314314
}
315315

316316
const auto encryptedAt = Timestamp::FromEpochMilli(reader.ReadInt64());
317-
const int siteId = reader.ReadInt32(); // NOLINT(clang-analyzer-deadcode.DeadStores)
317+
/*const int siteId = */ reader.ReadInt32();
318318
const std::int64_t keyId = reader.ReadInt32();
319319
const auto* const key = keys.Get(keyId);
320320
if (key == nullptr) {
@@ -351,7 +351,7 @@ static DecryptionDataResult DecryptDataV3(const std::vector<std::uint8_t>& encry
351351

352352
BigEndianByteReader payloadReader(payload.data(), payloadLen);
353353
const auto encryptedAt = Timestamp::FromEpochMilli(payloadReader.ReadInt64());
354-
const int siteId = payloadReader.ReadInt32(); // NOLINT(clang-analyzer-deadcode.DeadStores)
354+
/*const int siteId = */ payloadReader.ReadInt32();
355355

356356
return DecryptionDataResult::MakeSuccess({payloadReader.GetCurrentData(), payloadReader.GetCurrentData() + payloadReader.GetRemainingSize()}, encryptedAt);
357357
}

test/base_64_encoding_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void VerifyEncodingDecodingTables(
1616
std::set<unsigned int> decodedValues;
1717
EXPECT_EQ(expectedEncodingTable.size(), 64);
1818
EXPECT_EQ(expectedEncodingTable.size(), encodingTableLen);
19-
for (int i = 0; i < expectedEncodingTable.size(); i++) {
19+
for (int i = 0; i < static_cast<int>(expectedEncodingTable.size()); i++) {
2020
EXPECT_EQ(expectedEncodingTable[i], encodingTable[i]);
2121
const char chr = expectedEncodingTable[i];
2222
const auto decoderTableIndex = static_cast<unsigned char>(chr);
@@ -27,7 +27,7 @@ static void VerifyEncodingDecodingTables(
2727

2828
// verify all the non-base64/base64url chars must have decoding value of 64 (b1000000)
2929
EXPECT_EQ(decodingTableLen, 256);
30-
for (int i = 0; i < decodingTableLen; i++) {
30+
for (unsigned int i = 0; i < decodingTableLen; i++) {
3131
if (decodedValues.find(i) == decodedValues.end()) {
3232
std::cout << i << std::endl;
3333
EXPECT_EQ(decodingTable[i], 64);

test/encryption_tests_v2.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ using namespace uid2;
1212

1313
static std::vector<std::uint8_t> GetMasterSecret();
1414
static std::vector<std::uint8_t> GetSiteSecret();
15-
static std::vector<std::uint8_t> MakeKeySecret(std::uint8_t v);
1615
static std::string KeySetToJson(const std::vector<Key>& keys);
1716
static std::vector<std::uint8_t> Base64Decode(const std::string& str);
1817

@@ -210,11 +209,6 @@ std::vector<std::uint8_t> GetSiteSecret()
210209
return {SITE_SECRET, SITE_SECRET + sizeof(SITE_SECRET)};
211210
}
212211

213-
std::vector<std::uint8_t> MakeKeySecret(std::uint8_t v)
214-
{
215-
return std::vector<std::uint8_t>(sizeof(SITE_SECRET), v); // NOLINT
216-
}
217-
218212
std::vector<std::uint8_t> Base64Decode(const std::string& str)
219213
{
220214
std::vector<std::uint8_t> result;

test/encryption_tests_v4.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ static std::string KeySetToJsonForSharing(const std::vector<Key>& keys);
2828

2929
static std::string KeySetToJsonForSharingWithHeader(const std::string& defaultKeyset, int callerSiteId, const std::vector<Key>& keys);
3030

31-
static std::vector<std::uint8_t> Base64Decode(const std::string& str);
32-
3331
static const int MASTER_KEYSET_ID = 1;
3432
static const int DEFAULT_KEYSET_ID = 99999;
35-
static const int TOKEN_EXPIRY_SECONDS = 86400;
3633
static const std::int64_t MASTER_KEY_ID = 164;
3734
static const std::int64_t SITE_KEY_ID = 165;
3835
static const int SITE_ID = 9000;
@@ -84,7 +81,7 @@ void crossPlatformConsistencyCheck_Base64UrlTest(const std::vector<std::uint8_t>
8481
std::vector<std::uint8_t> decoded;
8582
uid2::UID2Base64UrlCoder::Decode(base64UrlEncodedStr, decoded);
8683
EXPECT_EQ(rawInputLen, decoded.size());
87-
for (int i = 0; i < decoded.size(); i++) {
84+
for (size_t i = 0; i < decoded.size(); i++) {
8885
EXPECT_EQ(rawInput[i], decoded[i]);
8986
}
9087
}
@@ -542,10 +539,3 @@ std::vector<std::uint8_t> MakeKeySecret(std::uint8_t v)
542539
{
543540
return std::vector<std::uint8_t>(sizeof(SITE_SECRET), v); // NOLINT
544541
}
545-
546-
std::vector<std::uint8_t> Base64Decode(const std::string& str)
547-
{
548-
std::vector<std::uint8_t> result;
549-
macaron::Base64::Decode(str, result);
550-
return result;
551-
}

0 commit comments

Comments
 (0)