ceba1986 |
1 | /* -*-c-*- |
2 | * |
c6e0eaf0 |
3 | * $Id: base64.h,v 1.3 1999/12/10 23:42:04 mdw Exp $ |
ceba1986 |
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 $ |
c6e0eaf0 |
33 | * Revision 1.3 1999/12/10 23:42:04 mdw |
34 | * Change header file guard names. |
35 | * |
c601c4f1 |
36 | * Revision 1.2 1999/05/18 21:45:27 mdw |
37 | * Allow Base64 encode and decode of arbitrary rubbish. |
38 | * |
ceba1986 |
39 | * Revision 1.1 1999/05/17 20:35:00 mdw |
40 | * Base64 encoding and decoding support. |
41 | * |
42 | */ |
43 | |
c6e0eaf0 |
44 | #ifndef MLIB_BASE64_H |
45 | #define MLIB_BASE64_H |
ceba1986 |
46 | |
47 | #ifdef __cplusplus |
48 | extern "C" { |
49 | #endif |
50 | |
51 | /*----- Header files ------------------------------------------------------*/ |
52 | |
53 | #include "dstr.h" |
54 | |
55 | /*----- Data structures ---------------------------------------------------*/ |
56 | |
57 | typedef struct base64_ctx { |
58 | unsigned long acc; /* Accumulator for output data */ |
59 | unsigned qsz; /* Length of data queued */ |
60 | unsigned lnlen; /* Length of the current line */ |
61 | const char *indent; /* Newline-and-indent string */ |
62 | unsigned maxline; /* Maximum permitted line length */ |
63 | } base64_ctx; |
64 | |
65 | /*----- Functions provided ------------------------------------------------*/ |
66 | |
67 | /* --- @base64_encode@ --- * |
68 | * |
69 | * Arguments: @base64_ctx *ctx@ = pointer to a context block |
c601c4f1 |
70 | * @const void *p@ = pointer to a source buffer |
ceba1986 |
71 | * @size_t sz@ = size of the source buffer |
72 | * @dstr *d@ = pointer to destination string |
73 | * |
74 | * Returns: --- |
75 | * |
76 | * Use: Encodes a binary string in base64. To flush out the final |
77 | * few characters (if necessary), pass a null source pointer. |
78 | */ |
79 | |
80 | extern void base64_encode(base64_ctx */*ctx*/, |
c601c4f1 |
81 | const void */*p*/, size_t /*sz*/, |
ceba1986 |
82 | dstr */*d*/); |
83 | |
84 | /* --- @base64_decode@ --- * |
85 | * |
86 | * Arguments: @base64_ctx *ctx@ = pointer to a context block |
c601c4f1 |
87 | * @const void *p@ = pointer to a source buffer |
ceba1986 |
88 | * @size_t sz@ = size of the source buffer |
89 | * @dstr *d@ = pointer to destination string |
90 | * |
91 | * Returns: --- |
92 | * |
93 | * Use: Decodes a binary string in base64. To flush out the final |
94 | * few characters (if necessary), pass a null source pointer. |
95 | */ |
96 | |
97 | extern void base64_decode(base64_ctx */*ctx*/, |
c601c4f1 |
98 | const void */*p*/, size_t /*sz*/, |
ceba1986 |
99 | dstr */*d*/); |
100 | |
101 | /* --- @base64_init@ --- * |
102 | * |
103 | * Arguments: @base64_ctx *ctx@ = pointer to context block to initialize |
104 | * |
105 | * Returns: --- |
106 | * |
107 | * Use: Initializes a base64 context properly. |
108 | */ |
109 | |
110 | extern void base64_init(base64_ctx */*ctx*/); |
111 | |
112 | /*----- That's all, folks -------------------------------------------------*/ |
113 | |
114 | #ifdef __cplusplus |
115 | } |
116 | #endif |
117 | |
118 | #endif |