3 * Base64 encoding and decoding
5 * (c) 1997 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
35 /*----- Header files ------------------------------------------------------*/
39 /*----- Data structures ---------------------------------------------------*/
41 typedef struct base64_ctx {
42 unsigned long acc; /* Accumulator for output data */
43 unsigned qsz; /* Length of data queued */
44 unsigned lnlen; /* Length of the current line */
45 const char *indent; /* Newline-and-indent string */
46 unsigned maxline; /* Maximum permitted line length */
49 /*----- Functions provided ------------------------------------------------*/
51 /* --- @base64_encode@ --- *
53 * Arguments: @base64_ctx *ctx@ = pointer to a context block
54 * @const void *p@ = pointer to a source buffer
55 * @size_t sz@ = size of the source buffer
56 * @dstr *d@ = pointer to destination string
60 * Use: Encodes a binary string in base64. To flush out the final
61 * few characters (if necessary), pass a null source pointer.
64 extern void base64_encode(base64_ctx */*ctx*/,
65 const void */*p*/, size_t /*sz*/,
68 /* --- @base64_decode@ --- *
70 * Arguments: @base64_ctx *ctx@ = pointer to a context block
71 * @const void *p@ = pointer to a source buffer
72 * @size_t sz@ = size of the source buffer
73 * @dstr *d@ = pointer to destination string
77 * Use: Decodes a binary string in base64. To flush out the final
78 * few characters (if necessary), pass a null source pointer.
81 extern void base64_decode(base64_ctx */*ctx*/,
82 const void */*p*/, size_t /*sz*/,
85 /* --- @base64_init@ --- *
87 * Arguments: @base64_ctx *ctx@ = pointer to context block to initialize
91 * Use: Initializes a base64 context properly.
94 extern void base64_init(base64_ctx */*ctx*/);
96 /*----- That's all, folks -------------------------------------------------*/