mirror of
https://github.com/curl/curl.git
synced 2026-08-24 21:43:32 +03:00
var: add a '64dec' function that can base64 decode a string
Verified in test 455 and 487. If the provided string cannot be base64-decoded, it will instead use "[64dec-fail]" (without the quotes). Documented Ref: #16288 Closes #16330
This commit is contained in:
parent
54c07fd6c5
commit
a6e8ead533
6 changed files with 101 additions and 11 deletions
23
src/var.c
23
src/var.c
|
|
@ -91,6 +91,8 @@ static const struct tool_var *varcontent(struct GlobalConfig *global,
|
|||
#define FUNC_URL_LEN (sizeof(FUNC_URL) - 1)
|
||||
#define FUNC_B64 "b64"
|
||||
#define FUNC_B64_LEN (sizeof(FUNC_B64) - 1)
|
||||
#define FUNC_64DEC "64dec" /* base64 decode */
|
||||
#define FUNC_64DEC_LEN (sizeof(FUNC_64DEC) - 1)
|
||||
|
||||
static ParameterError varfunc(struct GlobalConfig *global,
|
||||
char *c, /* content */
|
||||
|
|
@ -179,6 +181,27 @@ static ParameterError varfunc(struct GlobalConfig *global,
|
|||
break;
|
||||
}
|
||||
}
|
||||
else if(FUNCMATCH(f, FUNC_64DEC, FUNC_64DEC_LEN)) {
|
||||
f += FUNC_64DEC_LEN;
|
||||
curlx_dyn_reset(out);
|
||||
if(clen) {
|
||||
unsigned char *enc;
|
||||
size_t elen;
|
||||
CURLcode result = curlx_base64_decode(c, &enc, &elen);
|
||||
/* put it in the output */
|
||||
if(result) {
|
||||
if(curlx_dyn_add(out, "[64dec-fail]"))
|
||||
err = PARAM_NO_MEM;
|
||||
}
|
||||
else {
|
||||
if(curlx_dyn_addn(out, enc, elen))
|
||||
err = PARAM_NO_MEM;
|
||||
curl_free(enc);
|
||||
}
|
||||
if(err)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* unsupported function */
|
||||
errorf(global, "unknown variable function in '%.*s'",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue