keystore_daemon/src/base64.cpp
size_t base64_encode_alloc (const char *in, size_t inlen, char **out)
{
    size_t outlen = 1 + BASE64_LENGTH (inlen);

    /* Check for overflow in outlen computation.
    *
    * If there is no overflow, outlen >= inlen.
    *
    * If the operation (inlen + 2) overflows then it yields at most +1, so
    * outlen is 0.
    *
    * If the multiplication overflows, we lose at least half of the
    * correct value, so the result is < ((inlen + 2) / 3) * 2, which is
    * less than (inlen + 2) * 0.66667, which is less than inlen as soon as
    * (inlen > 4).
    */
    if (inlen > outlen)
    {
        *out = NULL;
        return 0;
    }

    *out = (char *)malloc (outlen);
    if (!*out)
        return outlen;

    base64_encode (in, inlen, *out, outlen);

    return outlen - 1;
}
/* Allocate a buffer and store zero terminated base64 encoded data
   from array IN of size INLEN, returning BASE64_LENGTH(INLEN), i.e.,
   the length of the encoded data, excluding the terminating zero.  On
   return, the OUT variable will hold a pointer to newly allocated
   memory that must be deallocated by the caller.  If output string
   length would overflow, 0 is returned and OUT is set to NULL.  If
   memory allocation failed, OUT is set to NULL, and the return value
   indicates length of the requested memory block, i.e.,
   BASE64_LENGTH(inlen) + 1. */
Allocate a buffer and store zero terminated base64 encoded data
from array IN of size INLEN, returning BASE64_LENGTH(INLEN), i.e.,
the length of the encoded data, excluding the terminating zero.  On
return, the OUT variable will hold a pointer to newly allocated
memory that must be deallocated by the caller.  If output string
length would overflow, 0 is returned and OUT is set to NULL.  If
memory allocation failed, OUT is set to NULL, and the return value
indicates length of the requested memory block, i.e.,
BASE64_LENGTH(inlen) + 1.
Allocate a buffer and store zero terminated base64 encoded data from array IN of size INLEN returning BASE64_LENGTH ( INLEN ) i . e . the length of the encoded data excluding the terminating zero . On return the OUT variable will hold a pointer to newly allocated memory that must be deallocated by the caller . If output string length would overflow 0 is returned and OUT is set to NULL . If memory allocation failed OUT is set to NULL and the return value indicates length of the requested memory block i . e . BASE64_LENGTH ( inlen ) + 1 .
size_t base64_encode_alloc (const char *in, size_t inlen, char **out)
{
    size_t outlen = 1 + BASE64_LENGTH (inlen);
    if (inlen > outlen)
    {
        *out = NULL;
        return 0;
    }
    *out = (char *)malloc (outlen);
    if (!*out)
        return outlen;
    base64_encode (in, inlen, *out, outlen);
    return outlen - 1;
}
size_t base64_encode_alloc ( const char * in , size_t inlen , char * * out ) { size_t outlen = 1 + BASE64_LENGTH ( inlen ) ; if ( inlen > outlen ) { * out = NULL ; return 0 ; } * out = ( char * ) malloc ( outlen ) ; if ( ! * out ) return outlen ; base64_encode ( in , inlen , * out , outlen ) ; return outlen - 1 ; }
Allocate a buffer and store zero terminated base64 encoded data
from array IN of size INLEN, returning BASE64_LENGTH(INLEN), i.e.,
the length of the encoded data, excluding the terminating zero.
Allocate a buffer and store zero terminated base64 encoded data from array IN of size INLEN returning BASE64_LENGTH ( INLEN ) i . e . the length of the encoded data excluding the terminating zero .
/* Check for overflow in outlen computation.
    *
    * If there is no overflow, outlen >= inlen.
    *
    * If the operation (inlen + 2) overflows then it yields at most +1, so
    * outlen is 0.
    *
    * If the multiplication overflows, we lose at least half of the
    * correct value, so the result is < ((inlen + 2) / 3) * 2, which is
    * less than (inlen + 2) * 0.66667, which is less than inlen as soon as
    * (inlen > 4).
    */