Skip to content

Commit f0d7934

Browse files
authored
SUPL identity fix (#37)
* fixed log-no-color * updated changelog * fix supl identity digit order * updated changelog
1 parent 3be9b28 commit f0d7934

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## []
4+
5+
- `--log-no-color` will also not print the reset color code
6+
- Update the digit order of SUPL identity encoding/decoding
7+
38
## [4.0.4] 2025-03-13
49

510
- Added `--log-no-color` to disable colored logging output

dependency/loglet/loglet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void log(char const* module, Level level, char const* message) {
164164
strftime(buffer, sizeof(buffer), "%y%m%d %H:%M:%S", std::localtime(&now_c));
165165

166166
auto start_color = level_to_color(level);
167-
auto stop_color = COLOR_RESET;
167+
auto stop_color = sColorEnabled ? COLOR_RESET : "";
168168

169169
auto file = stdout;
170170
if (level == Level::Error || level == Level::Warning) {

dependency/supl/decode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ static Identity decode_identity(SETId& set_id) {
6161
uint64_t msisdn = 0;
6262
for (size_t i = 0; i < input.size; i++) {
6363
auto byte = input.buf[i];
64-
auto first = static_cast<uint64_t>((byte >> 4) & 0xF);
65-
auto second = static_cast<uint64_t>((byte >> 0) & 0xF);
64+
auto first = static_cast<uint64_t>((byte >> 0) & 0xF);
65+
auto second = static_cast<uint64_t>((byte >> 4) & 0xF);
6666
if (first != 0xF) {
6767
msisdn = 10 * msisdn + first;
6868
}

dependency/supl/encode.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,22 @@ static OCTET_STRING binary_encoded_octet(size_t max_length, uint64_t from) {
9191
octet.buf = reinterpret_cast<uint8_t*>(calloc(1, octet.size));
9292
memset(octet.buf, 0xFF, octet.size);
9393

94-
auto index = 0;
95-
while (from > 0) {
96-
auto value = static_cast<uint8_t>((from % 10) & 0xF);
97-
from /= 10;
94+
auto length = 0;
95+
auto data = from;
96+
while (data > 0) {
97+
data /= 10;
98+
length++;
99+
}
100+
101+
auto offset = 2 * max_length - length;
102+
auto index = offset;
103+
data = from;
104+
while (data > 0 && index < 2 * max_length) {
105+
auto value = static_cast<uint8_t>((data % 10) & 0xF);
106+
data /= 10;
98107

99-
auto byte_index = 8 - 1 - (index / 2);
100-
if (index % 2 == 0) {
108+
auto byte_index = max_length - 1 - (index / 2);
109+
if (index % 2 == 1) {
101110
octet.buf[byte_index] &= 0xF0;
102111
octet.buf[byte_index] |= value;
103112
} else {

0 commit comments

Comments
 (0)