diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2025-04-01 13:16:46 +0200 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2025-04-01 13:16:46 +0200 |
commit | 9cfce7641110354761fb41f37b6277350c5f733e (patch) | |
tree | e6ab500cf18e251abed953b3b79653c8377b6195 /lib | |
parent | 4339b79c57547e25a358fe9cd78496f0944ad8d9 (diff) |
WIP: mbedtls: replace mbedtls_high_level_strerr and mbedtls_low_level_strerrbuild
Those are not supported in next mbedtls version
Diffstat (limited to 'lib')
-rw-r--r-- | lib/crypto-mbedtls.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/crypto-mbedtls.c b/lib/crypto-mbedtls.c index 20fff30..31b57f8 100644 --- a/lib/crypto-mbedtls.c +++ b/lib/crypto-mbedtls.c @@ -44,6 +44,15 @@ static mbedtls_entropy_context entropy; static void __attribute__((constructor)) load(); static void __attribute__((destructor)) unload(); +static void raise_mbedtls_exception(uc_vm_t *vm, int errnum, const char *msg) +{ + char buf[120] = ""; + + mbedtls_strerror(errnum, buf, sizeof(buf)); + uc_vm_raise_exception(vm, EXCEPTION_RUNTIME, msg, buf); +} + + static uc_value_t * md_digest(uc_vm_t *vm, size_t nargs) { @@ -268,9 +277,7 @@ pk_set_public_key(uc_vm_t *vm, size_t nargs) int err = mbedtls_pk_parse_public_key(&ctx->pk, (const unsigned char*)ucv_string_get(key), ucv_string_length(key)); if (err) - uc_vm_raise_exception(vm, EXCEPTION_RUNTIME, "not a valid DER key %s: %s", - mbedtls_high_level_strerr(err), - mbedtls_low_level_strerr(err)); + raise_mbedtls_exception(vm, err, "not a valid DER key %s"); return NULL; } @@ -376,9 +383,7 @@ pk_verify(uc_vm_t *vm, size_t nargs) hash, hash_size, (const unsigned char*)ucv_string_get(sig), ucv_string_length(sig)); if (err) { - uc_vm_raise_exception(vm, EXCEPTION_RUNTIME, "validation failed: %s: %s", - mbedtls_high_level_strerr(err), - mbedtls_low_level_strerr(err)); + raise_mbedtls_exception(vm, err, "validation failed: %s"); return FALSE; } |