Browse Source

[Minor] Add base64 check routine

tags/1.9.0
Vsevolod Stakhov 5 years ago
parent
commit
08a77ec01e
2 changed files with 33 additions and 0 deletions
  1. 24
    0
      src/libcryptobox/base64/base64.c
  2. 9
    0
      src/libcryptobox/cryptobox.h

+ 24
- 0
src/libcryptobox/base64/base64.c View File

@@ -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;
}

+ 9
- 0
src/libcryptobox/cryptobox.h View File

@@ -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_ */

Loading…
Cancel
Save