Description

When doing base58 encoding and decoding there is some issue with the decoded string.

Here is my code to ilustrate the issue :

    $var(Test) = "test_string";
$var(Test) = $(var(Test){s.encode.base58});
xerr("Test String encoded = STRING_BEGIN$var(Test)STRING_END");

$var(Test) = $(var(Test){s.decode.base58});
xerr("Test String decoded = STRING_BEGIN$var(Test)STRING_END");

It has the following output :

image.png (view on web)

I've inserted STRING_BEGIN and STRING_END in the log to be able to know when string ends.

After this i've tried to user {s.trim} method with no success. I've noticed that despite not printing correctly, the string's length is calculated correctly, so i did a manual substring and was able to fix it.

xerr("Test Base58");
$var(Test) = "test_string";
$var(Test) = $(var(Test){s.encode.base58});
xerr("Test String encoded = STRING_BEGIN$var(Test)STRING_END");

$var(Test) = $(var(Test){s.decode.base58});
xerr("Test String decoded = STRING_BEGIN$var(Test)STRING_END");

$var(Test) = $(var(Test){s.trim});
xerr("Test String decoded and trimmed = STRING_BEGIN$var(Test)STRING_END");

$var(substring_length) = $(var(Test){s.len}) - 1;
$var(Test) = $(var(Test){s.substr,0,$var(substring_length)});

xerr("Test String decoded and fixed = STRING_BEGIN$var(Test)STRING_END");

Output :

image.png (view on web)

All of this doesn't happen with method for base64 for example

Additional Information

version: kamailio 5.7.1 (x86_64/linux) 4238e4
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, MEM_JOIN_FREE, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: 4238e4
compiled on 12:39:30 Jun 29 2023 with gcc 4.8.5

CentOS 7


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <kamailio/kamailio/issues/3907@github.com>