@@@ man wip
[mLib] / codec / base64.3
CommitLineData
b6b9d458 1.\" -*-nroff-*-
fbf20b5b 2.TH base64 3 "20 June 1999" "Straylight/Edgeware" "mLib utilities library"
b6b9d458 3.SH NAME
236f657b 4base64, base32, hex \- obsolete binary encoding functions
08da152e 5.\" @base64_encode
6.\" @base64_decode
7.\" @base64_init
236f657b
MW
8.\" @base32_encode
9.\" @base32_decode
10.\" @base32_init
11.\" @hex_encode
12.\" @hex_decode
13.\" @hex_init
b6b9d458 14.SH SYNOPSIS
15.nf
d2a91066 16.B "#include <mLib/base64.h>"
236f657b
MW
17.B "#include <mLib/base32.h>"
18.B "#include <mLib/hex.h>"
b6b9d458 19
adec5584 20.ta 2n
4729aa69 21.B "typedef struct {"
adec5584
MW
22.B " char *indent;"
23.B " unsigned maxline;"
24.B " ..."
4729aa69
MW
25.B "} base64_ctx;"
26
adec5584 27.ta \w'\fBvoid base64_encode('u
b6b9d458 28.BI "void base64_encode(base64_ctx *" ctx ,
adec5584
MW
29.BI " const void *" p ", size_t " sz ,
30.BI " dstr *" d );
b6b9d458 31.BI "void base64_decode(base64_ctx *" ctx ,
adec5584
MW
32.BI " const void *" p ", size_t " sz ,
33.BI " dstr *" d );
b6b9d458 34.BI "void base64_init(base64_ctx *" ctx );
236f657b 35
adec5584 36.ta 2n
4729aa69 37.B "typedef struct {"
adec5584
MW
38.B " char *indent;"
39.B " unsigned maxline;"
40.B " ..."
4729aa69
MW
41.B "} base32_ctx;"
42
adec5584 43.ta \w'\fBvoid base32_encode('u
236f657b 44.BI "void base32_encode(base32_ctx *" ctx ,
adec5584
MW
45.BI " const void *" p ", size_t " sz ,
46.BI " dstr *" d );
236f657b 47.BI "void base32_decode(base32_ctx *" ctx ,
adec5584
MW
48.BI " const void *" p ", size_t " sz ,
49.BI " dstr *" d );
236f657b
MW
50.BI "void base32_init(base32_ctx *" ctx );
51
adec5584 52.ta 2n
4729aa69 53.B "typedef struct {"
adec5584
MW
54.B " char *indent;"
55.B " unsigned maxline;"
56.B " ..."
4729aa69
MW
57.B "} hex_ctx;"
58
adec5584 59.ta \w'\fBvoid hex_encode('u
236f657b 60.BI "void hex_encode(hex_ctx *" ctx ,
adec5584
MW
61.BI " const void *" p ", size_t " sz ,
62.BI " dstr *" d );
236f657b 63.BI "void hex_decode(hex_ctx *" ctx ,
adec5584
MW
64.BI " const void *" p ", size_t " sz ,
65.BI " dstr *" d );
236f657b 66.BI "void hex_init(hex_ctx *" ctx );
b6b9d458 67.fi
68.SH DESCRIPTION
69The
236f657b 70.BR base64 ,
e8d9f0df 71.BR base32 ,
236f657b
MW
72and
73.B hex
74functions perform encoding and decoding of arbitrary binary strings, as
75defined by RFC4648, but without error reporting. These functions are
76obsolete, and new applications should use the
77.BR codec (3)
78interface, which provides more encoding and decoding options, and proper
79error detection.
80.PP
81The interfaces to these sets of functions is very similar: in
82the following description,
83.I prefix
84stands for one of
85.BR base64 ,
86.BR base32 ,
87or
88.BR hex .
b6b9d458 89.PP
90Before encoding or decoding a string, a
91.I context
92(of type
236f657b 93.IB prefix _ctx \fR)
b6b9d458 94must be initialized, by passing it to
236f657b 95.IB prefix _init \fR.
b6b9d458 96The context contains data which must be retained between calls to encode
97or decode substrings. The
236f657b 98.IB prefix _init
b6b9d458 99function sets up initial values for the data, and sets up defaults for
100the output formatting settings (see below).
101.PP
102Encoding of a string is performed by the
236f657b 103.IB prefix _encode
b6b9d458 104function. It is passed a pointer to a context block
105.IR ctx ,
106the input substring to encode passed by address
107.I p
108and length
109.IR sz ,
110and a pointer to a dynamic string
111.I d
112in which to write its output (see
08da152e 113.BR dstr (3)
b6b9d458 114for details on dynamic strings). Once all the input data has been
115passed through
236f657b 116.IB prefix _encode
b6b9d458 117it is necessary to flush the final few bytes of output. This is
118achieved by passing
236f657b 119.I prefix _encode
b6b9d458 120a null pointer as its source argument. It is an error to attempt to
121continue encoding after flushing output.
122.PP
123The output of the
236f657b 124.IB prefix _encode
b6b9d458 125function is formatted into lines using values from the context
126structure. The
127.B indent
128member is a pointer to a null-terminated string which is used to
129separate the output lines. The default indent string contains only a
130newline character. The
131.B maxline
d2a91066 132member gives the maximum length of line that
236f657b 133.IB prefix _encode
b6b9d458 134is allowed to produce. If this is not a multiple of 4, it is rounded
135up to the next highest multiple of four before use. A value of zero
136instructs
236f657b 137.IB prefix _encode
b6b9d458 138not to perform line splitting: the output will be a single (possibly
139very long) output line. The default maximum line length is 72
140characters. You may set these parameters by direct assignment to the
141context structure once it has been initialized.
142.PP
143Decoding is performed similarly by the
236f657b 144.IB prefix _decode
b6b9d458 145function. The comments above about flushing output apply equally to
146decoding.
147.PP
236f657b
MW
148Decoding ignores all errors. In particular, whitespace is ignored, and
149in the case of Base64 and Base32 encodings, it also ignores
b6b9d458 150.RB ` = '
236f657b 151characters in the string.
b6b9d458 152.SH "SEE ALSO"
236f657b 153.BR codec (3),
08da152e 154.BR dstr (3),
155.BR mLib (3).
b6b9d458 156.SH AUTHOR
9b5ac6ff 157Mark Wooding, <mdw@distorted.org.uk>