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