]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Allow to fold base64 encoding of signatures
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 23 Oct 2018 15:08:07 +0000 (16:08 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 23 Oct 2018 15:33:06 +0000 (16:33 +0100)
src/lua/lua_rsa.c

index 17675e5486cfe8d9237876c7bca307d1636a11c8..39433a167b6ec51e2088532ed9ddeaedc2cfddd0 100644 (file)
@@ -557,10 +557,30 @@ static gint
 lua_rsa_signature_base64 (lua_State *L)
 {
        rspamd_fstring_t *sig = lua_check_rsa_sign (L, 1);
+       guint boundary = 0;
        gchar *b64;
        gsize outlen;
+       enum rspamd_newlines_type how = RSPAMD_TASK_NEWLINES_CRLF;
 
-       b64 = rspamd_encode_base64 (sig->str, sig->len, 0, &outlen);
+       if (lua_isnumber (L, 2)) {
+               boundary = lua_tonumber (L, 2);
+       }
+
+       if (lua_isstring (L, 3)) {
+               const gchar *how_str = lua_tostring (L, 3);
+
+               if (strcmp (how_str, "cr") == 0) {
+                       how = RSPAMD_TASK_NEWLINES_CR;
+               }
+               else if (strcmp (how_str, "lf") == 0) {
+                       how = RSPAMD_TASK_NEWLINES_LF;
+               }
+               else {
+                       how = RSPAMD_TASK_NEWLINES_CRLF;
+               }
+       }
+
+       b64 = rspamd_encode_base64_fold (sig->str, sig->len, boundary, &outlen, how);
 
        if (b64) {
                lua_pushlstring (L, b64, outlen);