#ifndef _FR_BASE64_H
# define _FR_BASE64_H
-/* Get size_t. */
-# include <stddef.h>
+#include <freeradius-devel/ident.h>
+RCSIDH(base64_h, "$Id$")
-/* Get bool. */
-# include <stdbool.h>
+# include <stddef.h>
/* This uses that the expression (n+(k-1))/k means the smallest
integer >= n/k, i.e., the ceiling of n/k. */
# define FR_BASE64_ENC_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
# define FR_BASE64_DEC_LENGTH(inlen) ((3 * (inlen / 4)) + 2)
-extern bool fr_isbase64 (char ch);
+extern int fr_isbase64 (char ch);
extern void fr_base64_encode (const char *in, size_t inlen,
char *out, size_t outlen);
extern size_t fr_base64_encode_alloc (const char *in, size_t inlen, char **out);
-extern bool fr_base64_decode (const char *in, size_t inlen,
- char *out, size_t *outlen);
+extern int fr_base64_decode (const char *in, size_t inlen,
+ char *out, size_t *outlen);
-extern bool fr_base64_decode_alloc (const char *in, size_t inlen,
- char **out, size_t *outlen);
+extern int fr_base64_decode_alloc (const char *in, size_t inlen,
+ char **out, size_t *outlen);
#endif /* BASE64_H */
\ No newline at end of file
#include <freeradius-devel/ident.h>
RCSID("$Id$")
-/* Get prototype. */
+#include <freeradius-devel/libradius.h>
#include <freeradius-devel/base64.h>
/* Get malloc. */
If OUTLEN is less than FR_BASE64_ENC_LENGTH(INLEN), write as many bytes as
possible. If OUTLEN is larger than FR_BASE64_ENC_LENGTH(INLEN), also zero
terminate the output buffer. */
-void
-fr_base64_encode (const char *in, size_t inlen,
- char *out, size_t outlen)
+void fr_base64_encode (const char *in, size_t inlen,
+ char *out, size_t outlen)
{
static const char b64str[64] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
};
#if UCHAR_MAX == 255
-# define uchar_in_range(c) true
+# define uchar_in_range(c) TRUE
#else
# define uchar_in_range(c) ((c) <= 255)
#endif
-/* Return true if CH is a character from the Base64 alphabet, and
- false otherwise. Note that '=' is padding and not considered to be
+/* Return TRUE if CH is a character from the Base64 alphabet, and
+ FALSE otherwise. Note that '=' is padding and not considered to be
part of the alphabet. */
-bool
-fr_isbase64 (char ch)
+int fr_isbase64 (char ch)
{
return uchar_in_range (to_uchar (ch)) && 0 <= b64[to_uchar (ch)];
}
/* Decode base64 encoded input array IN of length INLEN to output
- array OUT that can hold *OUTLEN bytes. Return true if decoding was
- successful, i.e. if the input was valid base64 data, false
+ array OUT that can hold *OUTLEN bytes. Return TRUE if decoding was
+ successful, i.e. if the input was valid base64 data, FALSE
otherwise. If *OUTLEN is too small, as many bytes as possible will
be written to OUT. On return, *OUTLEN holds the length of decoded
bytes in OUT. Note that as soon as any non-alphabet characters are
- encountered, decoding is stopped and false is returned. This means
+ encountered, decoding is stopped and FALSE is returned. This means
that, when applicable, you must remove any line terminators that is
part of the data stream before calling this function. */
-bool
-fr_base64_decode (const char *in, size_t inlen,
- char *out, size_t *outlen)
+int fr_base64_decode (const char *in, size_t inlen,
+ char *out, size_t *outlen)
{
size_t outleft = *outlen;
*outlen -= outleft;
if (inlen != 0)
- return false;
+ return FALSE;
- return true;
+ return TRUE;
}
/* Allocate an output buffer in *OUT, and decode the base64 encoded
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
+ 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
+ decoding and memory error.) The function returns FALSE if the
input was invalid, in which case *OUT is NULL and *OUTLEN is
undefined. */
-bool
-fr_base64_decode_alloc (const char *in, size_t inlen, char **out,
- size_t *outlen)
+int fr_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.
*out = malloc (needlen);
if (!*out)
- return true;
+ return TRUE;
if (!fr_base64_decode (in, inlen, *out, &needlen))
{
free (*out);
*out = NULL;
- return false;
+ return FALSE;
}
if (outlen)
*outlen = needlen;
- return true;
+ return TRUE;
}
\ No newline at end of file