#ifndef _B64_H_82b87916_ #define _B64_H_82b87916_ /* This file is in the public domain. */ #include /* * Base-64 encoding and decoding. */ /* * b64r_*: routines to do decoding. * * b64r_init(rfn,arg) initializes a base-64 decoding operation. rfn is * a function which returns successive encoded bytes; arg is an opaque * argument passed to rfn. The return value from rfn must be an * unsigned char, converted to int, or B64R_EOF (at the end of the * base-64 text) or B64R_ERR (if an error occurred). It returns a * handle. * b64r_get(handle) returns successive decoded bytes, or B64R_ERR on * error or B64R_EOF if/when the end of the encoded data is reached * without error. * b64r_done(handle) cleans up the handle. * * Note that there is code which assumes that B64R_EOF and B64R_ERR are * nonzero. */ extern void *b64r_init(int (*)(void *), void *); extern int b64r_get(void *); extern void b64r_done(void *); #define B64R_EOF (-1) #define B64R_ERR (-2) /* * b64w_*: routines to do encoding. * * b64w_init(wfn,arg) initializes a base-64 encoding operation. wfn is * called for each output character; arg is an opaque pointer passed * as the first arg to wfn. The return value is an opaque handle * suitable for passing to the other functions. * b64w_put(handle,byte) passes a byte of (unencoded) data to the * encoding operation. * b64w_done(handle) ends the encoding operation, flushing any buffered * data and writing any necessary terminator. It also cleans up and * frees the handle. */ extern void *b64w_init(void (*)(void *, int), void *); extern void b64w_put(void *, int); extern void b64w_done(void *); /* * Utility and auxiliary routines. * * b64_stdio_get is suitable for use as a read function to b64r_init * when input simply comes from a stdio stream; the arg is the FILE *. * b64_stdio_put is suitable for use as a write function to b64w_init * when output simply goes to a stdio stream; the arg is the FILE *. * b64_read_blob(fp,blobp,lenp) reads a base-64 encoded blob from a * FILE *, storing the resulting decoded blob data pointer and length * through the other two arguments. It returns 0 on failure and 1 on * success. On success, the returned data is in malloc()ed memory * which the caller is responsible for freeing. * b64w_wrap(fp) wraps a stdio stream in a base-64 encoding layer. The * returned stream should ahve the unencoded data written to it, then * closed; the encoded data is written to the argument stream. Writes * to the argument stream after writing to, but before closing, the * returned stream will interleave the encoded data with the written * data in some unspecified way. * b64_write_blob(fp,data,len) writes the data blob in data and len, * encoded, to fp, with suitable termination. */ extern int b64_stdio_get(void *); extern void b64_stdio_put(void *, int); extern int b64_read_blob(FILE *, void **, int *); extern FILE *b64w_wrap(FILE *); extern void b64_write_blob(FILE *, const void *, int); /* * Encoded data written with these routines is suitable for reading * back with these routines only when it is followed by a character * which cannot be mistaken for a base-64 character. The encoding is * self-terminating when the (unencoded) length mod 3 is 1 or 2, but * not when it's 0. */ #endif