ESAPI-C 1.0
The OWASP Enterprise Security API for C

base64.c File Reference

A Base64 Encoding module implementation. More...

#include "base64.h"
#include <stdlib.h>
#include <limits.h>

Go to the source code of this file.

Defines

#define B64(_)
#define uchar_in_range(c)   ((c) <= 255)

Functions

void base64_encode (const char *in, size_t inlen, char *out, size_t outlen)
 Base64 encodes the given input character array to the given output buffer.
size_t base64_encode_alloc (const char *in, size_t inlen, char **out)
bool isbase64 (char ch)
 Determines if the given character is within the Base64 encoding character set.
bool base64_decode (const char *in, size_t inlen, char *out, size_t *outlen)
 Base64 decodes the given input character array to the given output buffer.
bool base64_decode_alloc (const char *in, size_t inlen, char **out, size_t *outlen)

Detailed Description

A Base64 Encoding module implementation.

Written by Simon Josefsson. Partially adapted from GNU MailUtils (mailbox/filter_trans.c, as of 2004-11-28). Improved by review from Paul Eggert, Bruno Haible, and Stepan Kasal.

See also RFC 3548 <http://www.ietf.org/rfc/rfc3548.txt>.

Be careful with error checking. Here is how you would typically use these functions:

 bool ok = base64_decode_alloc (in, inlen, &out, &outlen);
 if (!ok)
   FAIL: input was not valid base64
 if (out == NULL)
   FAIL: memory allocation error
 OK: data in OUT/OUTLEN

 size_t outlen = base64_encode_alloc (in, inlen, &out);
 if (out == NULL && outlen == 0 && inlen != 0)
   FAIL: input too long
 if (out == NULL)
   FAIL: memory allocation error
 OK: data in OUT/OUTLEN.
Since:
January 30, 2011

Definition in file base64.c.

 All Data Structures Files Functions Variables Typedefs Defines