예제 #1
0
/***
 * @method cryptobox_hash:hex()
 * Finalizes hash and return it as hex string
 * @return {string} hex value of hash
 */
static gint
lua_cryptobox_hash_hex (lua_State *L)
{
	struct rspamd_lua_cryptobox_hash *h = lua_check_cryptobox_hash (L, 1);
	guchar out[rspamd_cryptobox_HASHBYTES],
		out_hex[rspamd_cryptobox_HASHBYTES * 2 + 1];
	guint dlen;

	if (h && !h->is_finished) {
		memset (out_hex, 0, sizeof (out_hex));

		if (h->is_ssl) {
			dlen = sizeof (out);
			EVP_DigestFinal_ex (h->c, out, &dlen);
		}
		else {
			dlen = sizeof (out);
			rspamd_cryptobox_hash_final (h->h, out);
		}

		rspamd_encode_hex_buf (out, dlen, out_hex, sizeof (out_hex));
		lua_pushstring (L, out_hex);
		h->is_finished = TRUE;
	}
	else {
		return luaL_error (L, "invalid arguments");
	}

	return 1;
}
예제 #2
0
/***
 * @method cryptobox_hash:hex()
 * Finalizes hash and return it as hex string
 * @return {string} hex value of hash
 */
static gint
lua_cryptobox_hash_hex (lua_State *L)
{
	rspamd_cryptobox_hash_state_t *h = lua_check_cryptobox_hash (L, 1);
	guchar out[rspamd_cryptobox_HASHBYTES],
		out_hex[rspamd_cryptobox_HASHBYTES * 2 + 1];

	if (h) {
		memset (out_hex, 0, sizeof (out_hex));
		rspamd_cryptobox_hash_final (h, out);
		rspamd_encode_hex_buf (out, sizeof (out), out_hex, sizeof (out_hex));

		lua_pushstring (L, out_hex);
	}
	else {
		return luaL_error (L, "invalid arguments");
	}

	return 1;
}