From 630708c3eb1be4cdeb61e483e3eea091461a6378 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 1 Jul 2025 16:45:55 +0200 Subject: [PATCH] support function --- client/src/util.c | 26 ++++++++++++++++++++++++++ client/src/util.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/client/src/util.c b/client/src/util.c index 541b67dd8..ff71b74e1 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -1212,6 +1212,29 @@ void binstr_2_bytes(uint8_t *target, size_t *targetlen, const char *src) { } } +void binstr_2_u8(char *src, uint8_t n, uint8_t *dest) { + + uint8_t b = 0; + // Process binary string + for (uint8_t i = 0; i < n; ++i) { + b = (b << 1) | (src[i] == '1'); + } + if (dest) { + *dest = b; + } +} + +void binstr_2_u16(char *src, uint8_t n, uint16_t *dest) { + uint16_t b = 0; + // Process binary string + for (uint8_t i = 0; i < n; ++i) { + b = (b << 1) | (src[i] == '1'); + } + if (dest) { + *dest = b; + } +} + void hex_xor(uint8_t *d, const uint8_t *x, int n) { while (n--) { d[n] ^= x[n]; @@ -1611,6 +1634,9 @@ size_t unduplicate(uint8_t *d, size_t n, const uint8_t item_n) { if (n == 0) { return 0; } + if (n == 1) { + return 1; + } int write_index = 0; diff --git a/client/src/util.h b/client/src/util.h index c80e602f4..186f2e2a7 100644 --- a/client/src/util.h +++ b/client/src/util.h @@ -141,6 +141,9 @@ int binstr_2_binarray(uint8_t *target, char *source, int length); void bytes_2_binstr(char *target, const uint8_t *source, size_t sourcelen); void binstr_2_bytes(uint8_t *target, size_t *targetlen, const char *src); +void binstr_2_u8(char *src, uint8_t n, uint8_t *dest); +void binstr_2_u16(char *src, uint8_t n, uint16_t *dest); + void hex_xor(uint8_t *d, const uint8_t *x, int n); void hex_xor_token(uint8_t *d, const uint8_t *x, int dn, int xn);