chiark / gitweb /
Add a slew of manual pages.
[mLib] / man / base64.3
CommitLineData
b6b9d458 1.\" -*-nroff-*-
2.TH base64 3mLib "20 June 1999" mLib
3.SH NAME
4base64 \- conversion to and from base64 encoding
5.SH SYNOPSIS
6.nf
7.B "#include <mLib/base64.h>
8
9.BI "void base64_encode(base64_ctx *" ctx ,
10.BI " const void *" p ", size_t " sz ,
11.BI " dstr *" d );
12.BI "void base64_decode(base64_ctx *" ctx ,
13.BI " const void *" p ", size_t " sz ,
14.BI " dstr *" d );
15.BI "void base64_init(base64_ctx *" ctx );
16.fi
17.SH DESCRIPTION
18The
19.B base64
20functions perform base64 encoding and decoding of arbitrary binary
21strings. The base64 encoding is defined by RFC2045.
22.PP
23Before encoding or decoding a string, a
24.I context
25(of type
26.BR base64_ctx )
27must be initialized, by passing it to
28.BR base64_init .
29The context contains data which must be retained between calls to encode
30or decode substrings. The
31.B base64_init
32function sets up initial values for the data, and sets up defaults for
33the output formatting settings (see below).
34.PP
35Encoding of a string is performed by the
36.B base64_encode
37function. It is passed a pointer to a context block
38.IR ctx ,
39the input substring to encode passed by address
40.I p
41and length
42.IR sz ,
43and a pointer to a dynamic string
44.I d
45in which to write its output (see
46.BR dstr (3mLib)
47for details on dynamic strings). Once all the input data has been
48passed through
49.B base64_encode
50it is necessary to flush the final few bytes of output. This is
51achieved by passing
52.B base64_encode
53a null pointer as its source argument. It is an error to attempt to
54continue encoding after flushing output.
55.PP
56The output of the
57.B base64_encode
58function is formatted into lines using values from the context
59structure. The
60.B indent
61member is a pointer to a null-terminated string which is used to
62separate the output lines. The default indent string contains only a
63newline character. The
64.B maxline
65member gives the maxmimum length of line that
66.B base64_encode
67is allowed to produce. If this is not a multiple of 4, it is rounded
68up to the next highest multiple of four before use. A value of zero
69instructs
70.B base64_encode
71not to perform line splitting: the output will be a single (possibly
72very long) output line. The default maximum line length is 72
73characters. You may set these parameters by direct assignment to the
74context structure once it has been initialized.
75.PP
76Decoding is performed similarly by the
77.B base64_decode
78function. The comments above about flushing output apply equally to
79decoding.
80.PP
81Decoding ignores all whitespace characters in the encoded string. It
82also ignores
83.RB ` = '
84characters in the string and works out the final block length
85automatically based on the input size.
86.SH "SEE ALSO"
87.BR dstr (3mLib).
88.SH AUTHOR
89Mark Wooding, <mdw@nsict.org>