chiark / gitweb /
codec/{base32,hex}.h: Include `codec.h'.
[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
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 );
236f657b
MW
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 );
b6b9d458 43.fi
44.SH DESCRIPTION
45The
236f657b
MW
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 .
b6b9d458 65.PP
66Before encoding or decoding a string, a
67.I context
68(of type
236f657b 69.IB prefix _ctx \fR)
b6b9d458 70must be initialized, by passing it to
236f657b 71.IB prefix _init \fR.
b6b9d458 72The context contains data which must be retained between calls to encode
73or decode substrings. The
236f657b 74.IB prefix _init
b6b9d458 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
236f657b 79.IB prefix _encode
b6b9d458 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
08da152e 89.BR dstr (3)
b6b9d458 90for details on dynamic strings). Once all the input data has been
91passed through
236f657b 92.IB prefix _encode
b6b9d458 93it is necessary to flush the final few bytes of output. This is
94achieved by passing
236f657b 95.I prefix _encode
b6b9d458 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
236f657b 100.IB prefix _encode
b6b9d458 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
d2a91066 108member gives the maximum length of line that
236f657b 109.IB prefix _encode
b6b9d458 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
236f657b 113.IB prefix _encode
b6b9d458 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
236f657b 120.IB prefix _decode
b6b9d458 121function. The comments above about flushing output apply equally to
122decoding.
123.PP
236f657b
MW
124Decoding ignores all errors. In particular, whitespace is ignored, and
125in the case of Base64 and Base32 encodings, it also ignores
b6b9d458 126.RB ` = '
236f657b 127characters in the string.
b6b9d458 128.SH "SEE ALSO"
236f657b 129.BR codec (3),
08da152e 130.BR dstr (3),
131.BR mLib (3).
b6b9d458 132.SH AUTHOR
9b5ac6ff 133Mark Wooding, <mdw@distorted.org.uk>