Skip to content

Commit

Permalink
Added hextobin xlat.
Browse files Browse the repository at this point in the history
It's useful for creating binary nonsense
  • Loading branch information
alandekok committed Apr 11, 2014
1 parent 8ecd25f commit f254d71
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/modules/rlm_expr/rlm_expr.c
Expand Up @@ -691,6 +691,27 @@ EVP_MD_XLAT(sha256);
EVP_MD_XLAT(sha512);
#endif

/**
* @brief Encode string or attribute from hex to binary
*
* Example: "%{hextobin:0x616161}" == "aaa"
*/
static ssize_t hex_to_bin_xlat(UNUSED void *instance, UNUSED REQUEST *request,
char const *fmt, char *out, size_t outlen)
{
ssize_t inlen;
uint8_t const *p;

inlen = xlat_fmt_to_ref(&p, request, fmt);
if (inlen < 0) {
return -1;
}

if ((p[0] != '0') && (p[1] != 'x')) return -1;

return fr_hex2bin((uint8_t *) out, (char *) p + 2, outlen);
}

/**
* @brief Encode string or attribute as base64
*
Expand Down Expand Up @@ -789,6 +810,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
#endif
xlat_register("base64", base64_xlat, NULL, inst);
xlat_register("base64tohex", base64_to_hex_xlat, NULL, inst);
xlat_register("hextobin", hex_to_bin_xlat, NULL, inst);

/*
* Initialize various paircompare functions
Expand Down

0 comments on commit f254d71

Please sign in to comment.