xref: /netbsd-src/external/mpl/bind/dist/lib/isccc/include/isccc/base64.h (revision bcda20f65a8566e103791ec395f7f499ef322704)
1 /*	$NetBSD: base64.h,v 1.7 2025/01/26 16:25:44 christos Exp $	*/
2 
3 /*
4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5  *
6  * SPDX-License-Identifier: MPL-2.0 AND ISC
7  *
8  * This Source Code Form is subject to the terms of the Mozilla Public
9  * License, v. 2.0. If a copy of the MPL was not distributed with this
10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11  *
12  * See the COPYRIGHT file distributed with this work for additional
13  * information regarding copyright ownership.
14  */
15 
16 /*
17  * Copyright (C) 2001 Nominum, Inc.
18  *
19  * Permission to use, copy, modify, and/or distribute this software for any
20  * purpose with or without fee is hereby granted, provided that the above
21  * copyright notice and this permission notice appear in all copies.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
24  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY
26  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
27  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
28  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
29  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30  */
31 
32 #pragma once
33 
34 /*! \file isccc/base64.h */
35 
36 #include <isc/lang.h>
37 
38 #include <isccc/types.h>
39 
40 ISC_LANG_BEGINDECLS
41 
42 /***
43  *** Functions
44  ***/
45 
46 isc_result_t
47 isccc_base64_encode(isccc_region_t *source, int wordlength,
48 		    const char *wordbreak, isccc_region_t *target);
49 /*%<
50  * Convert data into base64 encoded text.
51  *
52  * Notes:
53  *\li	The base64 encoded text in 'target' will be divided into
54  *	words of at most 'wordlength' characters, separated by
55  * 	the 'wordbreak' string.  No parentheses will surround
56  *	the text.
57  *
58  * Requires:
59  *\li	'source' is a region containing binary data.
60  *\li	'target' is a text region containing available space.
61  *\li	'wordbreak' points to a null-terminated string of
62  *		zero or more whitespace characters.
63  */
64 
65 isc_result_t
66 isccc_base64_decode(const char *cstr, isccc_region_t *target);
67 /*%<
68  * Decode a null-terminated base64 string.
69  *
70  * Requires:
71  *\li	'cstr' is non-null.
72  *\li	'target' is a valid region.
73  *
74  * Returns:
75  *\li	#ISC_R_SUCCESS	-- the entire decoded representation of 'cstring'
76  *			   fit in 'target'.
77  *\li	#ISC_R_BADBASE64 -- 'cstr' is not a valid base64 encoding.
78  *\li	#ISC_R_NOSPACE	-- 'target' is not big enough.
79  */
80 
81 ISC_LANG_ENDDECLS
82