diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-04-09 17:13:12 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-04-09 17:13:12 +0100 |
commit | c2351037b581724ce6d6cbcf4da5a0115b87c8de (patch) | |
tree | d55bd57d8bda456308b21cba7827fb2e2fc272a0 /src/libutil/str_util.c | |
parent | f5c0d7116e373fa48ab465e8d8dcae1ddaf44932 (diff) | |
download | rspamd-c2351037b581724ce6d6cbcf4da5a0115b87c8de.tar.gz rspamd-c2351037b581724ce6d6cbcf4da5a0115b87c8de.zip |
[Feature] Support multiple base32 alphabets
Diffstat (limited to 'src/libutil/str_util.c')
-rw-r--r-- | src/libutil/str_util.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index 4c16cb685..473e68782 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -539,10 +539,11 @@ rspamd_str_pool_copy (gconstpointer data, gpointer ud) */ gint -rspamd_encode_base32_buf (const guchar *in, gsize inlen, gchar *out, - gsize outlen) +rspamd_encode_base32_buf (const guchar *in, gsize inlen, gchar *out, gsize outlen, + enum rspamd_base32_type type) { - static const char b32[]="ybndrfg8ejkmcpqxot1uwisza345h769"; + static const char b32_default[] = "ybndrfg8ejkmcpqxot1uwisza345h769", + b32_bleach[] = "qpzry9x8gf2tvdw0s3jn54khce6mua7l", *b32; gchar *o, *end; gsize i; gint remain = -1, x; @@ -550,6 +551,18 @@ rspamd_encode_base32_buf (const guchar *in, gsize inlen, gchar *out, end = out + outlen; o = out; + switch (type) { + case RSPAMD_BASE32_DEFAULT: + b32 = b32_default; + break; + case RSPAMD_BASE32_BLEACH: + b32 = b32_bleach; + break; + default: + g_assert_not_reached (); + abort (); + } + for (i = 0; i < inlen && o < end - 1; i++) { switch (i % 5) { case 0: @@ -603,14 +616,15 @@ rspamd_encode_base32_buf (const guchar *in, gsize inlen, gchar *out, } gchar * -rspamd_encode_base32 (const guchar *in, gsize inlen) +rspamd_encode_base32 (const guchar *in, gsize inlen, enum rspamd_base32_type type) { gsize allocated_len = inlen * 8 / 5 + 2; gchar *out; gint outlen; out = g_malloc (allocated_len); - outlen = rspamd_encode_base32_buf (in, inlen, out, allocated_len - 1); + outlen = rspamd_encode_base32_buf (in, inlen, out, + allocated_len - 1, type); if (outlen >= 0) { out[outlen] = 0; |