Working version of libexim-encrypt-dlfunc-decrypt-secretbox

This commit is contained in:
Heiko Reese
2021-09-11 02:06:19 +02:00
parent 41e7c43ab8
commit ad3437f5df
2 changed files with 47 additions and 21 deletions

View File

@ -58,17 +58,14 @@ typedef struct {
size_t length;
} Password;
Password base64_decode_string(const char *input) {
Password p;
void base64_decode_string(const char *input, unsigned char **outstring, size_t *outlen) {
size_t input_len = strlen(input);
size_t outmaxlen = input_len / 4 * 3;
p.string = malloc(outmaxlen);
int b64err = sodium_base642bin(p.string, outmaxlen, (const char *) input, input_len,
NULL, &p.length, NULL, sodium_base64_VARIANT_ORIGINAL);
*outstring = malloc(outmaxlen * sizeof(unsigned char));
int b64err = sodium_base642bin(*outstring, outmaxlen, (const char *) input, input_len,
NULL, outlen, NULL, sodium_base64_VARIANT_ORIGINAL);
if (b64err != 0) {
fprintf(stderr, "[ERROR] Unable to base64-decode the password\n");
exit(EXIT_FAILURE);
}
return p;
}