xref: /openbsd/usr.bin/dig/lib/isc/include/isc/base32.h (revision 5dea098c)
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 #ifndef ISC_BASE32_H
18 #define ISC_BASE32_H 1
19 
20 /*! \file */
21 
22 /*
23  * Routines for manipulating base 32 and base 32 hex encoded data.
24  * Based on RFC 4648.
25  *
26  * Base 32 hex preserves the sort order of data when it is encoded /
27  * decoded.
28  *
29  * Base 32 hex "np" is base 32 hex but no padding is produced or accepted.
30  */
31 
32 #include <isc/types.h>
33 
34 /***
35  *** Functions
36  ***/
37 
38 isc_result_t
39 isc_base32hexnp_totext(isc_region_t *source, int wordlength,
40 		       const char *wordbreak, isc_buffer_t *target);
41 /*!<
42  * \brief Convert data into base32 encoded text.
43  *
44  * Notes:
45  *\li	The base32 encoded text in 'target' will be divided into
46  *	words of at most 'wordlength' characters, separated by
47  * 	the 'wordbreak' string.  No parentheses will surround
48  *	the text.
49  *
50  * Requires:
51  *\li	'source' is a region containing binary data
52  *\li	'target' is a text buffer containing available space
53  *\li	'wordbreak' points to a null-terminated string of
54  *		zero or more whitespace characters
55  *
56  * Ensures:
57  *\li	target will contain the base32 encoded version of the data
58  *	in source.  The 'used' pointer in target will be advanced as
59  *	necessary.
60  */
61 
62 isc_result_t
63 isc_base32hexnp_decoderegion(isc_region_t *source, isc_buffer_t *target);
64 /*!<
65  * \brief Decode a packed (no white space permitted) region in
66  * base32, base32hex or base32hex non-padded.
67  *
68  * Requires:
69  *\li   'source' is a valid region.
70  *\li   'target' is a valid buffer.
71  *
72  * Returns:
73  *\li   #ISC_R_SUCCESS  -- the entire decoded representation of 'cstring'
74  *                         fit in 'target'.
75  *\li   #ISC_R_BADBASE32 -- 'source' is not a valid base32 encoding.
76  */
77 
78 #endif /* ISC_BASE32_H */
79