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