xref: /dragonfly/lib/libc/net/base64.3 (revision 8f2ce533)
1.\" Copyright (c) 2022 The DragonFly Project.  All rights reserved.
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
6.\"
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in
11.\"    the documentation and/or other materials provided with the
12.\"    distribution.
13.\" 3. Neither the name of The DragonFly Project nor the names of its
14.\"    contributors may be used to endorse or promote products derived
15.\"    from this software without specific, prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
21.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
23.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.Dd May 1, 2022
31.Dt BASE64 3
32.Os
33.Sh NAME
34.Nm base64 ,
35.Nm b64_ntop ,
36.Nm b64_pton
37.Nd base64 encode and decode
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In resolv.h
42.Ft int
43.Fo b64_ntop
44.Fa "const unsigned char *src"
45.Fa "size_t srclength"
46.Fa "char *target"
47.Fa "size_t targsize"
48.Fc
49.Ft int
50.Fo b64_pton
51.Fa "const char *src"
52.Fa "unsigned char *target"
53.Fa "size_t targsize"
54.Fc
55.Sh DESCRIPTION
56.Fn B64_ntop
57encodes the input data
58.Fa src
59of length
60.Fa srclength ,
61and writes the encoded string to
62.Fa target
63of capacity
64.Fa targsize .
65The output buffer
66.Fa target
67should be big enough to hold the encoded string,
68including the terminating NUL character.
69On success,
70.Fa target
71holds the encoded string and its length
72(without accounting for the NUL terminator) is returned.
73Otherwise, a value of \-1 is returned.
74.Pp
75.Fn B64_pton
76decodes the base64 string
77.Fa src
78and writes the decoded data to
79.Fa target
80of capacity
81.Fa targsize .
82On success,
83.Fa target
84holds the decoded data and its length is returned.
85Otherwise, a value of \-1 is returned.
86If the output buffer
87.Fa target
88is
89.Dv NULL ,
90.Fn b64_pton
91returns the required length to hold the decoded data.
92.Sh RETURN VALUES
93The
94.Nm base64
95functions return the length of the result if successful;
96otherwise the value \-1 is returned.
97.Sh SEE ALSO
98.Xr openssl 1
99.Rs
100.%R RFC
101.%N 1521
102.%D September 1993
103.%T "MIME (Multipurpose Internet Mail Extensions) Part One"
104.Re
105.Sh HISTORY
106The
107.Nm base64
108functions appeared in
109.Fx 3.0 .
110.Sh AUTHORS
111.An -nosplit
112This manual page was written by
113.An Aaron LI Aq Mt aly@aaronly.me .
114