view src/lib/base64.h @ 765:553f050c8313 HEAD

Added buffer API. Point is to hide all buffer writing behind this API which verifies that nothing overflows. Much better than doing the same checks all around the code, even if it is slightly slower. Buffer reading is still mostly done directly, that isn't such a big security risk and I can't think of a reasonable API for it anyway.
author Timo Sirainen <tss@iki.fi>
date Sun, 08 Dec 2002 07:23:07 +0200
parents debb8468514e
children fd8888f6f037
line wrap: on
line source

#ifndef __BASE64_H
#define __BASE64_H

/* Translates binary data into base64. The src must not point to dest buffer.
   Returns 1 if all ok, 0 if dest buffer got full. */
int base64_encode(const unsigned char *src, size_t src_size, Buffer *dest);

/* Translates base64 data into binary and appends it to dest buffer. dest may
   point to same buffer as src. Returns 1 if all ok, 0 if dest buffer got full
   or -1 if data is invalid. Any CR, LF characters are ignored, as well as
   whitespace at beginning or end of line.

   This function may be called multiple times for parsing the same stream.
   If src_pos is non-NULL, it's updated to first non-translated character in
   src. */
int base64_decode(const unsigned char *src, size_t src_size,
		  size_t *src_pos_r, Buffer *dest);

/* max. buffer size required for base64_encode() */
#define MAX_BASE64_ENCODED_SIZE(size) \
	((size) / 3 * 4 + 2+2)
/* max. buffer size required for base64_decode() */
#define MAX_BASE64_DECODED_SIZE(size) \
	((size) / 4 * 3 + 3)
#endif