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