Base64 encoding and decoding support.
[mLib] / base64.h
1 /* -*-c-*-
2 *
3 * $Id: base64.h,v 1.1 1999/05/17 20:35:00 mdw Exp $
4 *
5 * Base64 encoding and decoding
6 *
7 * (c) 1997 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the mLib utilities library.
13 *
14 * mLib is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * mLib is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
25 * License along with mLib; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA.
28 */
29
30 /*----- Revision history --------------------------------------------------*
31 *
32 * $Log: base64.h,v $
33 * Revision 1.1 1999/05/17 20:35:00 mdw
34 * Base64 encoding and decoding support.
35 *
36 */
37
38 #ifndef BASE64_H
39 #define BASE64_H
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /*----- Header files ------------------------------------------------------*/
46
47 #include "dstr.h"
48
49 /*----- Data structures ---------------------------------------------------*/
50
51 typedef struct base64_ctx {
52 unsigned long acc; /* Accumulator for output data */
53 unsigned qsz; /* Length of data queued */
54 unsigned lnlen; /* Length of the current line */
55 const char *indent; /* Newline-and-indent string */
56 unsigned maxline; /* Maximum permitted line length */
57 } base64_ctx;
58
59 /*----- Functions provided ------------------------------------------------*/
60
61 /* --- @base64_encode@ --- *
62 *
63 * Arguments: @base64_ctx *ctx@ = pointer to a context block
64 * @const unsigned char *src@ = pointer to a source buffer
65 * @size_t sz@ = size of the source buffer
66 * @dstr *d@ = pointer to destination string
67 *
68 * Returns: ---
69 *
70 * Use: Encodes a binary string in base64. To flush out the final
71 * few characters (if necessary), pass a null source pointer.
72 */
73
74 extern void base64_encode(base64_ctx */*ctx*/,
75 const unsigned char */*src*/, size_t /*sz*/,
76 dstr */*d*/);
77
78 /* --- @base64_decode@ --- *
79 *
80 * Arguments: @base64_ctx *ctx@ = pointer to a context block
81 * @const unsigned char *src@ = pointer to a source buffer
82 * @size_t sz@ = size of the source buffer
83 * @dstr *d@ = pointer to destination string
84 *
85 * Returns: ---
86 *
87 * Use: Decodes a binary string in base64. To flush out the final
88 * few characters (if necessary), pass a null source pointer.
89 */
90
91 extern void base64_decode(base64_ctx */*ctx*/,
92 const unsigned char */*src*/, size_t /*sz*/,
93 dstr */*d*/);
94
95 /* --- @base64_init@ --- *
96 *
97 * Arguments: @base64_ctx *ctx@ = pointer to context block to initialize
98 *
99 * Returns: ---
100 *
101 * Use: Initializes a base64 context properly.
102 */
103
104 extern void base64_init(base64_ctx */*ctx*/);
105
106 /*----- That's all, folks -------------------------------------------------*/
107
108 #ifdef __cplusplus
109 }
110 #endif
111
112 #endif