Files
ZephCore/tests/support/identity_utils_boundary.cpp
T
2026-10-15 21:34:26 +02:00

53 lines
2.2 KiB
C++

#include <mesh/Utils.h>
#include <stdexcept>
#include <cstring>
// Identity tests exercise fromSeed, sign/verify, ECDH and storage serialization.
// Other constructors/private-key recovery need Utils.cpp/PSA integration later.
// Fail loudly if a new test accidentally reaches those unimplemented boundaries.
// Hex helpers are pure; copied from src/Utils.cpp for the prefs.json tests
// (ConfigSerializer stores binary blobs as hex).
static uint8_t hexVal(char c) {
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
if (c >= '0' && c <= '9') return c - '0';
return 0;
}
bool mesh::Utils::fromHex(uint8_t *dest, int dest_size, const char *src_hex) {
size_t len = strlen(src_hex);
if (len != (size_t)(dest_size * 2)) return false;
uint8_t *dp = dest;
while ((size_t)(dp - dest) < (size_t)dest_size) {
char ch = *src_hex++;
char cl = *src_hex++;
*dp++ = (uint8_t)((hexVal(ch) << 4) | hexVal(cl));
}
return true;
}
void mesh::Utils::printHex(Stream &s, const uint8_t *src, size_t len) {
static const char hex_chars[] = "0123456789ABCDEF";
while (len > 0) {
uint8_t b = *src++;
s.print(hex_chars[b >> 4]);
s.print(hex_chars[b & 0x0F]);
len--;
}
}
void mesh::Utils::secureZeroize(void*, size_t) {
throw std::runtime_error("Identity RNG/recovery path requires real Utils integration");
}
bool mesh::Utils::constantTimeEqual(const void*, const void*, size_t) {
throw std::runtime_error("Identity validation requires real Utils integration");
}
// KissModem's hash and encrypt/decrypt commands (not exercised by its tests;
// the one-fragment sha256 is hash_capture.cpp's).
void mesh::Utils::sha256(uint8_t*, size_t, const uint8_t*, int, const uint8_t*, int) {
throw std::runtime_error("KISS hash command requires real Utils integration");
}
int mesh::Utils::encryptThenMAC(const uint8_t*, uint8_t*, const uint8_t*, int) {
throw std::runtime_error("KISS encrypt command requires real Utils integration");
}
int mesh::Utils::MACThenDecrypt(const uint8_t*, uint8_t*, const uint8_t*, int) {
throw std::runtime_error("KISS decrypt command requires real Utils integration");
}