From aed148fd3035e7392e52a71f82b576f52d8986c3 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 5 Feb 2016 23:05:13 +0000 Subject: Add fixed hex/base32 encode and decode routines --- src/libutil/str_util.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/libutil/str_util.h') diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h index 2f16db37d..8e26b37dc 100644 --- a/src/libutil/str_util.h +++ b/src/libutil/str_util.h @@ -131,6 +131,50 @@ gchar * rspamd_encode_hex (const guchar *in, gsize inlen); */ guchar* rspamd_decode_hex (const gchar *in, gsize inlen); +/** + * Encode string using base32 encoding + * @param in input + * @param inlen input length + * @param out output buf + * @param outlen output buf len + * @return encoded len if `outlen` is enough to encode `inlen` + */ +gint rspamd_encode_base32_buf (const guchar *in, gsize inlen, gchar *out, + gsize outlen); + +/** + * Decode string using base32 encoding + * @param in input + * @param inlen input length + * @param out output buf (may overlap with `in`) + * @param outlen output buf len + * @return decoded len if in is valid base32 and `outlen` is enough to encode `inlen` + */ +gint rspamd_decode_base32_buf (const gchar *in, gsize inlen, + guchar *out, gsize outlen); + +/** + * Encode string using hex encoding + * @param in input + * @param inlen input length + * @param out output buf + * @param outlen output buf len + * @return encoded len if `outlen` is enough to encode `inlen` + */ +gint rspamd_encode_hex_buf (const guchar *in, gsize inlen, gchar *out, + gsize outlen); + +/** + * Decode string using hex encoding + * @param in input + * @param inlen input length + * @param out output buf (may overlap with `in`) + * @param outlen output buf len + * @return decoded len if in is valid hex and `outlen` is enough to encode `inlen` + */ +gint rspamd_decode_hex_buf (const gchar *in, gsize inlen, + guchar *out, gsize outlen); + /** * Encode string using base64 encoding * @param in input -- cgit v1.2.3