xref: /openbsd-src/usr.bin/dig/lib/isc/include/isc/base64.h (revision afc94c37458f3fb1a93f727a90bf1f56b6e5eee6)
1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14  * PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /* $Id: base64.h,v 1.4 2020/02/23 23:40:22 jsg Exp $ */
18 
19 #ifndef ISC_BASE64_H
20 #define ISC_BASE64_H 1
21 
22 /*! \file isc/base64.h */
23 
24 #include <isc/types.h>
25 
26 /***
27  *** Functions
28  ***/
29 
30 isc_result_t
31 isc_base64_totext(isc_region_t *source, int wordlength,
32 		  const char *wordbreak, isc_buffer_t *target);
33 /*!<
34  * \brief Convert data into base64 encoded text.
35  *
36  * Notes:
37  *\li	The base64 encoded text in 'target' will be divided into
38  *	words of at most 'wordlength' characters, separated by
39  * 	the 'wordbreak' string.  No parentheses will surround
40  *	the text.
41  *
42  * Requires:
43  *\li	'source' is a region containing binary data
44  *\li	'target' is a text buffer containing available space
45  *\li	'wordbreak' points to a null-terminated string of
46  *		zero or more whitespace characters
47  *
48  * Ensures:
49  *\li	target will contain the base64 encoded version of the data
50  *	in source.  The 'used' pointer in target will be advanced as
51  *	necessary.
52  */
53 
54 isc_result_t
55 isc_base64_decodestring(const char *cstr, isc_buffer_t *target);
56 /*!<
57  * \brief Decode a null-terminated base64 string.
58  *
59  * Requires:
60  *\li	'cstr' is non-null.
61  *\li	'target' is a valid buffer.
62  *
63  * Returns:
64  *\li	#ISC_R_SUCCESS	-- the entire decoded representation of 'cstring'
65  *			   fit in 'target'.
66  *\li	#ISC_R_BADBASE64 -- 'cstr' is not a valid base64 encoding.
67  *
68  * 	Other error returns are any possible error code from:
69  *\li		isc_lex_create(),
70  */
71 
72 #endif /* ISC_BASE64_H */
73