2 * Copyright (C) 2008 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.
17 /* $Id: base32.h,v 1.3 2008/09/25 04:02:39 tbox Exp $ */
20 #define ISC_BASE32_H 1
25 * Routines for manipulating base 32 and base 32 hex encoded data.
28 * Base 32 hex preserves the sort order of data when it is encoded /
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 * \brief Convert data into base32 encoded text.
51 *\li The base32 encoded text in 'target' will be divided into
52 * words of at most 'wordlength' characters, separated by
53 * the 'wordbreak' string. No parentheses will surround
57 *\li 'source' is a region containing binary data
58 *\li 'target' is a text buffer containing available space
59 *\li 'wordbreak' points to a null-terminated string of
60 * zero or more whitespace characters
63 *\li target will contain the base32 encoded version of the data
64 * in source. The 'used' pointer in target will be advanced as
69 isc_base32_decodestring(const char *cstr, isc_buffer_t *target);
71 isc_base32hex_decodestring(const char *cstr, isc_buffer_t *target);
73 * \brief Decode a null-terminated base32 string.
76 *\li 'cstr' is non-null.
77 *\li 'target' is a valid buffer.
80 *\li #ISC_R_SUCCESS -- the entire decoded representation of 'cstring'
82 *\li #ISC_R_BADBASE32 -- 'cstr' is not a valid base32 encoding.
84 * Other error returns are any possible error code from:
85 *\li isc_lex_create(),
86 *\li isc_lex_openbuffer(),
87 *\li isc_base32_tobuffer().
91 isc_base32_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
93 isc_base32hex_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
95 * \brief Convert base32 encoded text from a lexer context into data.
98 *\li 'lex' is a valid lexer context
99 *\li 'target' is a buffer containing binary data
100 *\li 'length' is an integer
103 *\li target will contain the data represented by the base32 encoded
104 * string parsed by the lexer. No more than length bytes will be read,
105 * if length is positive. The 'used' pointer in target will be
106 * advanced as necessary.
110 isc_base32_decoderegion(isc_region_t *source, isc_buffer_t *target);
112 isc_base32hex_decoderegion(isc_region_t *source, isc_buffer_t *target);
114 * \brief Decode a packed (no white space permitted) base32 region.
117 *\li 'source' is a valid region.
118 *\li 'target' is a valid buffer.
121 *\li #ISC_R_SUCCESS -- the entire decoded representation of 'cstring'
123 *\li #ISC_R_BADBASE32 -- 'source' is not a valid base32 encoding.
128 #endif /* ISC_BASE32_H */