chiark / gitweb /
codec/{base32,hex}.h: Include `codec.h'.
[mLib] / codec / base64.h
CommitLineData
ceba1986 1/* -*-c-*-
ceba1986 2 *
3 * Base64 encoding and decoding
4 *
5 * (c) 1997 Straylight/Edgeware
6 */
7
d4efbcd9 8/*----- Licensing notice --------------------------------------------------*
ceba1986 9 *
10 * This file is part of the mLib utilities library.
11 *
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.
d4efbcd9 16 *
ceba1986 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.
d4efbcd9 21 *
ceba1986 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,
25 * MA 02111-1307, USA.
26 */
27
c6e0eaf0 28#ifndef MLIB_BASE64_H
29#define MLIB_BASE64_H
ceba1986 30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35/*----- Header files ------------------------------------------------------*/
36
236f657b
MW
37#ifndef MLIB_CODEC_H
38# include "codec.h"
39#endif
40
dd3c57bc
MW
41#ifndef MLIB_DSTR_H
42# include "dstr.h"
43#endif
ceba1986 44
45/*----- Data structures ---------------------------------------------------*/
46
47typedef struct base64_ctx {
48 unsigned long acc; /* Accumulator for output data */
49 unsigned qsz; /* Length of data queued */
50 unsigned lnlen; /* Length of the current line */
236f657b 51 char *indent; /* Newline-and-indent string */
ceba1986 52 unsigned maxline; /* Maximum permitted line length */
53} base64_ctx;
54
55/*----- Functions provided ------------------------------------------------*/
56
57/* --- @base64_encode@ --- *
58 *
59 * Arguments: @base64_ctx *ctx@ = pointer to a context block
c601c4f1 60 * @const void *p@ = pointer to a source buffer
ceba1986 61 * @size_t sz@ = size of the source buffer
62 * @dstr *d@ = pointer to destination string
63 *
64 * Returns: ---
65 *
66 * Use: Encodes a binary string in base64. To flush out the final
67 * few characters (if necessary), pass a null source pointer.
68 */
69
70extern void base64_encode(base64_ctx */*ctx*/,
c601c4f1 71 const void */*p*/, size_t /*sz*/,
ceba1986 72 dstr */*d*/);
73
74/* --- @base64_decode@ --- *
75 *
76 * Arguments: @base64_ctx *ctx@ = pointer to a context block
c601c4f1 77 * @const void *p@ = pointer to a source buffer
ceba1986 78 * @size_t sz@ = size of the source buffer
79 * @dstr *d@ = pointer to destination string
80 *
81 * Returns: ---
82 *
83 * Use: Decodes a binary string in base64. To flush out the final
84 * few characters (if necessary), pass a null source pointer.
85 */
86
87extern void base64_decode(base64_ctx */*ctx*/,
c601c4f1 88 const void */*p*/, size_t /*sz*/,
ceba1986 89 dstr */*d*/);
90
91/* --- @base64_init@ --- *
92 *
93 * Arguments: @base64_ctx *ctx@ = pointer to context block to initialize
94 *
95 * Returns: ---
96 *
97 * Use: Initializes a base64 context properly.
98 */
99
100extern void base64_init(base64_ctx */*ctx*/);
101
236f657b
MW
102/*----- Codec object interface --------------------------------------------*/
103
104extern const codec_class base64_class, file64_class, base64url_class;
105
ceba1986 106/*----- That's all, folks -------------------------------------------------*/
107
108#ifdef __cplusplus
109 }
110#endif
111
112#endif