2 * Copyright (C) 2008, 2014 Internet Systems Consortium, Inc. ("ISC")
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.
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.
18 #define ISC_BASE32_H 1
23 * Routines for manipulating base 32 and base 32 hex encoded data.
26 * Base 32 hex preserves the sort order of data when it is encoded /
29 * Base 32 hex "np" is base 32 hex but no padding is produced or accepted.
33 #include <isc/types.h>
42 isc_base32_totext(isc_region_t *source, int wordlength,
43 const char *wordbreak, isc_buffer_t *target);
45 isc_base32hex_totext(isc_region_t *source, int wordlength,
46 const char *wordbreak, isc_buffer_t *target);
48 isc_base32hexnp_totext(isc_region_t *source, int wordlength,
49 const char *wordbreak, isc_buffer_t *target);
51 * \brief Convert data into base32 encoded text.
54 *\li The base32 encoded text in 'target' will be divided into
55 * words of at most 'wordlength' characters, separated by
56 * the 'wordbreak' string. No parentheses will surround
60 *\li 'source' is a region containing binary data
61 *\li 'target' is a text buffer containing available space
62 *\li 'wordbreak' points to a null-terminated string of
63 * zero or more whitespace characters
66 *\li target will contain the base32 encoded version of the data
67 * in source. The 'used' pointer in target will be advanced as
72 isc_base32_decodestring(const char *cstr, isc_buffer_t *target);
74 isc_base32hex_decodestring(const char *cstr, isc_buffer_t *target);
76 isc_base32hexnp_decodestring(const char *cstr, isc_buffer_t *target);
78 * \brief Decode a null-terminated string in base32, base32hex, or
79 * base32hex non-padded.
82 *\li 'cstr' is non-null.
83 *\li 'target' is a valid buffer.
86 *\li #ISC_R_SUCCESS -- the entire decoded representation of 'cstring'
88 *\li #ISC_R_BADBASE32 -- 'cstr' is not a valid base32 encoding.
90 * Other error returns are any possible error code from:
91 *\li isc_lex_create(),
92 *\li isc_lex_openbuffer(),
93 *\li isc_base32_tobuffer().
97 isc_base32_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
99 isc_base32hex_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
101 isc_base32hexnp_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
103 * \brief Convert text encoded in base32, base32hex, or base32hex
104 * non-padded from a lexer context into data.
107 *\li 'lex' is a valid lexer context
108 *\li 'target' is a buffer containing binary data
109 *\li 'length' is an integer
112 *\li target will contain the data represented by the base32 encoded
113 * string parsed by the lexer. No more than length bytes will be read,
114 * if length is positive. The 'used' pointer in target will be
115 * advanced as necessary.
119 isc_base32_decoderegion(isc_region_t *source, isc_buffer_t *target);
121 isc_base32hex_decoderegion(isc_region_t *source, isc_buffer_t *target);
123 isc_base32hexnp_decoderegion(isc_region_t *source, isc_buffer_t *target);
125 * \brief Decode a packed (no white space permitted) region in
126 * base32, base32hex or base32hex non-padded.
129 *\li 'source' is a valid region.
130 *\li 'target' is a valid buffer.
133 *\li #ISC_R_SUCCESS -- the entire decoded representation of 'cstring'
135 *\li #ISC_R_BADBASE32 -- 'source' is not a valid base32 encoding.
140 #endif /* ISC_BASE32_H */