chiark / gitweb /
precomp: New directory for precomputed files.
[mLib] / codec / base32.h
CommitLineData
1c4fa429 1/* -*-c-*-
1c4fa429 2 *
3 * Base32 encoding and decoding
4 *
5 * (c) 1997 Straylight/Edgeware
6 */
7
d4efbcd9 8/*----- Licensing notice --------------------------------------------------*
1c4fa429 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 *
1c4fa429 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 *
1c4fa429 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
28#ifndef MLIB_BASE32_H
29#define MLIB_BASE32_H
30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35/*----- Header files ------------------------------------------------------*/
36
dd3c57bc
MW
37#ifndef MLIB_DSTR_H
38# include "dstr.h"
39#endif
1c4fa429 40
41/*----- Data structures ---------------------------------------------------*/
42
43typedef struct base32_ctx {
44 unsigned long accl, acch; /* Accumulator for output data */
45 unsigned qsz; /* Length of data queued */
46 unsigned lnlen; /* Length of the current line */
47 const char *indent; /* Newline-and-indent string */
48 unsigned maxline; /* Maximum permitted line length */
49} base32_ctx;
50
51/*----- Functions provided ------------------------------------------------*/
52
53/* --- @base32_encode@ --- *
54 *
55 * Arguments: @base32_ctx *ctx@ = pointer to a context block
56 * @const void *p@ = pointer to a source buffer
57 * @size_t sz@ = size of the source buffer
58 * @dstr *d@ = pointer to destination string
59 *
60 * Returns: ---
61 *
62 * Use: Encodes a binary string in base32. To flush out the final
63 * few characters (if necessary), pass a null source pointer.
64 */
65
66extern void base32_encode(base32_ctx */*ctx*/,
67 const void */*p*/, size_t /*sz*/,
68 dstr */*d*/);
69
70/* --- @base32_decode@ --- *
71 *
72 * Arguments: @base32_ctx *ctx@ = pointer to a context block
73 * @const void *p@ = pointer to a source buffer
74 * @size_t sz@ = size of the source buffer
75 * @dstr *d@ = pointer to destination string
76 *
77 * Returns: ---
78 *
79 * Use: Decodes a binary string in base32. To flush out the final
80 * few characters (if necessary), pass a null source pointer.
81 */
82
83extern void base32_decode(base32_ctx */*ctx*/,
84 const void */*p*/, size_t /*sz*/,
85 dstr */*d*/);
86
87/* --- @base32_init@ --- *
88 *
89 * Arguments: @base32_ctx *ctx@ = pointer to context block to initialize
90 *
91 * Returns: ---
92 *
93 * Use: Initializes a base32 context properly.
94 */
95
96extern void base32_init(base32_ctx */*ctx*/);
97
98/*----- That's all, folks -------------------------------------------------*/
99
100#ifdef __cplusplus
101 }
102#endif
103
104#endif