}
/***
- * @method cryptobox_signature:base32()
+ * @method cryptobox_signature:base32([b32type='default'])
* Return base32 encoded signature string
+ * @param {string} b32type base32 type (default, bleach, rfc)
* @return {string} raw value of signature
*/
static gint
LUA_TRACE_POINT;
rspamd_fstring_t *sig = lua_check_cryptobox_sign (L, 1);
gchar *encoded;
+ enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT;
+
+ if (lua_type (L, 2) == LUA_TSTRING) {
+ btype = rspamd_base32_decode_type_from_str (lua_tostring (L, 2));
+
+ if (btype == RSPAMD_BASE32_INVALID) {
+ return luaL_error (L, "invalid b32 type: %s", lua_tostring (L, 2));
+ }
+ }
if (sig) {
- encoded = rspamd_encode_base32 (sig->str, sig->len, RSPAMD_BASE32_DEFAULT);
+ encoded = rspamd_encode_base32 (sig->str, sig->len, btype);
lua_pushstring (L, encoded);
g_free (encoded);
}
}
/***
- * @method cryptobox_hash:base32()
- * Finalizes hash and return it as zbase32 string
+ * @method cryptobox_hash:base32([b32type])
+ * Finalizes hash and return it as zbase32 (by default) string
+ * @param {string} b32type base32 type (default, bleach, rfc)
* @return {string} base32 value of hash
*/
static gint
guint dlen;
if (h && !h->is_finished) {
+ enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT;
+
+ if (lua_type (L, 2) == LUA_TSTRING) {
+ btype = rspamd_base32_decode_type_from_str (lua_tostring (L, 2));
+
+ if (btype == RSPAMD_BASE32_INVALID) {
+ return luaL_error (L, "invalid b32 type: %s", lua_tostring (L, 2));
+ }
+ }
+
memset (out_b32, 0, sizeof (out_b32));
lua_cryptobox_hash_finish (h, out, &dlen);
r = out;
}
}
- rspamd_encode_base32_buf (r, dlen, out_b32, sizeof (out_b32), RSPAMD_BASE32_DEFAULT);
+ rspamd_encode_base32_buf (r, dlen, out_b32, sizeof (out_b32), btype);
lua_pushstring (L, out_b32);
h->is_finished = TRUE;
}
LUA_FUNCTION_DEF (util, decode_base64);
/***
- * @function util.encode_base32(input)
+ * @function util.encode_base32(input, [b32type = 'default'])
* Encodes data in base32 breaking lines if needed
* @param {text or string} input input data
+ * @param {string} b32type base32 type (default, bleach, rfc)
* @return {rspamd_text} encoded data chunk
*/
LUA_FUNCTION_DEF (util, encode_base32);
/***
- * @function util.decode_base32(input)
+ * @function util.decode_base32(input, [b32type = 'default'])
* Decodes data from base32 ignoring whitespace characters
* @param {text or string} input data to decode
+ * @param {string} b32type base32 type (default, bleach, rfc)
* @return {rspamd_text} decoded data chunk
*/
LUA_FUNCTION_DEF (util, decode_base32);
struct rspamd_lua_text *t;
const gchar *s = NULL;
gchar *out;
+ enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT;
gsize inlen, outlen;
if (lua_type (L, 1) == LUA_TSTRING) {
}
}
+ if (lua_type (L, 2) == LUA_TSTRING) {
+ btype = rspamd_base32_decode_type_from_str (lua_tostring (L, 2));
+
+ if (btype == RSPAMD_BASE32_INVALID) {
+ return luaL_error (L, "invalid b32 type: %s", lua_tostring (L, 2));
+ }
+ }
+
if (s == NULL) {
- lua_pushnil (L);
+ return luaL_error (L, "invalid arguments");
}
else {
- out = rspamd_encode_base32 (s, inlen, RSPAMD_BASE32_DEFAULT);
+ out = rspamd_encode_base32 (s, inlen, btype);
if (out != NULL) {
t = lua_newuserdata (L, sizeof (*t));
struct rspamd_lua_text *t;
const gchar *s = NULL;
gsize inlen, outlen;
+ enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT;
if (lua_type (L, 1) == LUA_TSTRING) {
s = luaL_checklstring (L, 1, &inlen);
}
}
+ if (lua_type (L, 2) == LUA_TSTRING) {
+ btype = rspamd_base32_decode_type_from_str (lua_tostring (L, 2));
+
+ if (btype == RSPAMD_BASE32_INVALID) {
+ return luaL_error (L, "invalid b32 type: %s", lua_tostring (L, 2));
+ }
+ }
+
if (s != NULL) {
t = lua_newuserdata (L, sizeof (*t));
rspamd_lua_setclass (L, "rspamd{text}", -1);
- t->start = rspamd_decode_base32 (s, inlen, &outlen, RSPAMD_BASE32_DEFAULT);
+ t->start = rspamd_decode_base32 (s, inlen, &outlen, btype);
t->len = outlen;
t->flags = RSPAMD_TEXT_FLAG_OWN;
}