aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcryptobox
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-02-11 14:14:53 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-02-11 14:14:53 +0000
commit08a77ec01eabb4e10d0750427925610ecada3686 (patch)
tree963a531ee641323f405a597af113d1c08026fe34 /src/libcryptobox
parentc82b20c9ee82a0d204f7367e93d2f87a74154c52 (diff)
downloadrspamd-08a77ec01eabb4e10d0750427925610ecada3686.tar.gz
rspamd-08a77ec01eabb4e10d0750427925610ecada3686.zip
[Minor] Add base64 check routine
Diffstat (limited to 'src/libcryptobox')
-rw-r--r--src/libcryptobox/base64/base64.c24
-rw-r--r--src/libcryptobox/cryptobox.h9
2 files changed, 33 insertions, 0 deletions
diff --git a/src/libcryptobox/base64/base64.c b/src/libcryptobox/base64/base64.c
index b4ddd3135..ff08b9a80 100644
--- a/src/libcryptobox/base64/base64.c
+++ b/src/libcryptobox/base64/base64.c
@@ -146,3 +146,27 @@ base64_test (bool generic, size_t niters, size_t len)
return cycles;
}
+
+
+gboolean
+rspamd_cryptobox_base64_is_valid (const gchar *in, gsize inlen)
+{
+ const guchar *p, *end;
+
+ if (inlen == 0) {
+ return FALSE;
+ }
+
+ p = in;
+ end = in + inlen;
+
+ while (p < end && *p != '=') {
+ if (!g_ascii_isspace (*p)) {
+ if (base64_table_dec[*p] == 255) {
+ return FALSE;
+ }
+ }
+ }
+
+ return TRUE;
+} \ No newline at end of file
diff --git a/src/libcryptobox/cryptobox.h b/src/libcryptobox/cryptobox.h
index 1d48c06e5..016e58fc2 100644
--- a/src/libcryptobox/cryptobox.h
+++ b/src/libcryptobox/cryptobox.h
@@ -399,4 +399,13 @@ guint64 rspamd_cryptobox_fast_hash_specific (
*/
gboolean rspamd_cryptobox_base64_decode (const gchar *in, gsize inlen,
guchar *out, gsize *outlen);
+
+/**
+ * Returns TRUE if data looks like a valid base64 string
+ * @param in
+ * @param inlen
+ * @return
+ */
+gboolean rspamd_cryptobox_base64_is_valid (const gchar *in, gsize inlen);
+
#endif /* CRYPTOBOX_H_ */