keystore_daemon/src/base64.cpp
bool base64_decode_alloc (const char *in, size_t inlen, char **out, size_t *outlen)
{
  /* This may allocate a few bytes too much, depending on input,
     but it's not worth the extra CPU time to compute the exact amount.
     The exact amount is 3 * inlen / 4, minus 1 if the input ends
     with "=" and minus another 1 if the input ends with "==".
     Dividing before multiplying avoids the possibility of overflow.  */
    size_t needlen = 3 * (inlen / 4) + 2;

    *out = (char *)malloc (needlen);
    if (!*out)
        return true;

    if (!base64_decode (in, inlen, *out, &needlen))
    {
        free (*out);
        *out = NULL;
        return false;
    }

    if (outlen)
        *outlen = needlen;

    return true;
}
/* Allocate an output buffer in *OUT, and decode the base64 encoded
   data stored in IN of size INLEN to the *OUT buffer.  On return, the
   size of the decoded data is stored in *OUTLEN.  OUTLEN may be NULL,
   if the caller is not interested in the decoded length.  *OUT may be
   NULL to indicate an out of memory error, in which case *OUTLEN
   contains the size of the memory block needed.  The function returns
   true on successful decoding and memory allocation errors.  (Use the
   *OUT and *OUTLEN parameters to differentiate between successful
   decoding and memory error.)  The function returns false if the
   input was invalid, in which case *OUT is NULL and *OUTLEN is
   undefined. */
Allocate an output buffer in *OUT, and decode the base64 encoded
data stored in IN of size INLEN to the *OUT buffer.  On return, the
size of the decoded data is stored in *OUTLEN.  OUTLEN may be NULL,
if the caller is not interested in the decoded length.  *OUT may be
NULL to indicate an out of memory error, in which case *OUTLEN
contains the size of the memory block needed.  The function returns
true on successful decoding and memory allocation errors.  (Use the
OUT and *OUTLEN parameters to differentiate between successful
decoding and memory error.)  The function returns false if the
input was invalid, in which case *OUT is NULL and *OUTLEN is
undefined.
Allocate an output buffer in * OUT and decode the base64 encoded data stored in IN of size INLEN to the * OUT buffer . On return the size of the decoded data is stored in * OUTLEN . OUTLEN may be NULL if the caller is not interested in the decoded length . * OUT may be NULL to indicate an out of memory error in which case * OUTLEN contains the size of the memory block needed . The function returns true on successful decoding and memory allocation errors . ( Use the OUT and * OUTLEN parameters to differentiate between successful decoding and memory error . ) The function returns false if the input was invalid in which case * OUT is NULL and * OUTLEN is undefined .
bool base64_decode_alloc (const char *in, size_t inlen, char **out, size_t *outlen)
{
    size_t needlen = 3 * (inlen / 4) + 2;
    *out = (char *)malloc (needlen);
    if (!*out)
        return true;
    if (!base64_decode (in, inlen, *out, &needlen))
    {
        free (*out);
        *out = NULL;
        return false;
    }
    if (outlen)
        *outlen = needlen;
    return true;
}
bool base64_decode_alloc ( const char * in , size_t inlen , char * * out , size_t * outlen ) { size_t needlen = 3 * ( inlen / 4 ) + 2 ; * out = ( char * ) malloc ( needlen ) ; if ( ! * out ) return true ; if ( ! base64_decode ( in , inlen , * out , & needlen ) ) { free ( * out ) ; * out = NULL ; return false ; } if ( outlen ) * outlen = needlen ; return true ; }
Allocate an output buffer in *OUT, and decode the base64 encoded
data stored in IN of size INLEN to the *OUT buffer.
Allocate an output buffer in * OUT and decode the base64 encoded data stored in IN of size INLEN to the * OUT buffer .
/* This may allocate a few bytes too much, depending on input,
     but it's not worth the extra CPU time to compute the exact amount.
     The exact amount is 3 * inlen / 4, minus 1 if the input ends
     with "=" and minus another 1 if the input ends with "==".
     Dividing before multiplying avoids the possibility of overflow.  */