commit baecba4: [Minor] Add helper to get base32 type

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Apr 10 10:49:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-04-10 11:27:08 +0100
URL: https://github.com/rspamd/rspamd/commit/baecba4ce93e91b553e2d5d0d8e779dcd05e1d43

[Minor] Add helper to get base32 type

---
 src/libutil/str_util.c | 22 ++++++++++++++++++++++
 src/libutil/str_util.h |  8 ++++++++
 2 files changed, 30 insertions(+)

diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index 3ea725738..b2c50cab7 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -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,
diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h
index 3a794bcc0..f6c2a1389 100644
--- a/src/libutil/str_util.h
+++ b/src/libutil/str_util.h
@@ -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


More information about the Commits mailing list