]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add helper to get base32 type
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 10 Apr 2020 10:27:08 +0000 (11:27 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 10 Apr 2020 10:44:46 +0000 (11:44 +0100)
src/libutil/str_util.c
src/libutil/str_util.h

index 3ea7257380b016c97ecd6e3269cd51e29c7a4d4b..b2c50cab7d7730fd66cb1e082f4f569f2b45b9c0 100644 (file)
@@ -642,6 +642,28 @@ rspamd_encode_base32 (const guchar *in, gsize inlen, enum rspamd_base32_type typ
        return NULL;
 }
 
+enum rspamd_base32_type
+rspamd_base32_decode_type_from_str (const gchar *str)
+{
+       enum rspamd_base32_type ret = RSPAMD_BASE32_INVALID;
+
+       if (str == NULL) {
+               return RSPAMD_BASE32_DEFAULT;
+       }
+
+       if (strcmp (str, "default") == 0 || strcmp (str, "zbase") == 0) {
+               ret = RSPAMD_BASE32_ZBASE;
+       }
+       else if (strcmp (str, "bleach") == 0) {
+               ret = RSPAMD_BASE32_BLEACH;
+       }
+       else if (strcmp (str, "rfc") == 0) {
+               ret = RSPAMD_BASE32_RFC;
+       }
+
+       return ret;
+}
+
 static const guchar b32_dec_zbase[] = {
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
index 3a794bcc0e973f74185eba10e11f165cdfe8c285..f6c2a13893a9e888a563d560e22cdb18c307a74d 100644 (file)
@@ -163,8 +163,16 @@ enum rspamd_base32_type {
        RSPAMD_BASE32_ZBASE = 0,
        RSPAMD_BASE32_BLEACH,
        RSPAMD_BASE32_RFC,
+       RSPAMD_BASE32_INVALID = -1,
 };
 
+/**
+ * Returns base32 type from a string or RSPAMD_BASE32_INVALID
+ * @param str
+ * @return
+ */
+enum rspamd_base32_type rspamd_base32_decode_type_from_str (const gchar *str);
+
 /**
  * Encode string using base32 encoding
  * @param in input