base32.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 #ifndef ISC_BASE32_H
00018 #define ISC_BASE32_H 1
00019 
00020 /*! \file */
00021 
00022 /*
00023  * Routines for manipulating base 32 and base 32 hex encoded data.
00024  * Based on RFC 4648.
00025  *
00026  * Base 32 hex preserves the sort order of data when it is encoded /
00027  * decoded.
00028  *
00029  * Base 32 hex "np" is base 32 hex but no padding is produced or accepted.
00030  */
00031 
00032 #include <isc/lang.h>
00033 #include <isc/types.h>
00034 
00035 ISC_LANG_BEGINDECLS
00036 
00037 /***
00038  *** Functions
00039  ***/
00040 
00041 isc_result_t
00042 isc_base32_totext(isc_region_t *source, int wordlength,
00043                   const char *wordbreak, isc_buffer_t *target);
00044 isc_result_t
00045 isc_base32hex_totext(isc_region_t *source, int wordlength,
00046                      const char *wordbreak, isc_buffer_t *target);
00047 isc_result_t
00048 isc_base32hexnp_totext(isc_region_t *source, int wordlength,
00049                        const char *wordbreak, isc_buffer_t *target);
00050 /*!<
00051  * \brief Convert data into base32 encoded text.
00052  *
00053  * Notes:
00054  *\li   The base32 encoded text in 'target' will be divided into
00055  *      words of at most 'wordlength' characters, separated by
00056  *      the 'wordbreak' string.  No parentheses will surround
00057  *      the text.
00058  *
00059  * Requires:
00060  *\li   'source' is a region containing binary data
00061  *\li   'target' is a text buffer containing available space
00062  *\li   'wordbreak' points to a null-terminated string of
00063  *              zero or more whitespace characters
00064  *
00065  * Ensures:
00066  *\li   target will contain the base32 encoded version of the data
00067  *      in source.  The 'used' pointer in target will be advanced as
00068  *      necessary.
00069  */
00070 
00071 isc_result_t
00072 isc_base32_decodestring(const char *cstr, isc_buffer_t *target);
00073 isc_result_t
00074 isc_base32hex_decodestring(const char *cstr, isc_buffer_t *target);
00075 isc_result_t
00076 isc_base32hexnp_decodestring(const char *cstr, isc_buffer_t *target);
00077 /*!<
00078  * \brief Decode a null-terminated string in base32, base32hex, or
00079  * base32hex non-padded.
00080  *
00081  * Requires:
00082  *\li   'cstr' is non-null.
00083  *\li   'target' is a valid buffer.
00084  *
00085  * Returns:
00086  *\li   #ISC_R_SUCCESS  -- the entire decoded representation of 'cstring'
00087  *                         fit in 'target'.
00088  *\li   #ISC_R_BADBASE32 -- 'cstr' is not a valid base32 encoding.
00089  *
00090  *      Other error returns are any possible error code from:
00091  *\li           isc_lex_create(),
00092  *\li           isc_lex_openbuffer(),
00093  *\li           isc_base32_tobuffer().
00094  */
00095 
00096 isc_result_t
00097 isc_base32_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
00098 isc_result_t
00099 isc_base32hex_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
00100 isc_result_t
00101 isc_base32hexnp_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
00102 /*!<
00103  * \brief Convert text encoded in base32, base32hex, or base32hex
00104  * non-padded from a lexer context into data.
00105  *
00106  * Requires:
00107  *\li   'lex' is a valid lexer context
00108  *\li   'target' is a buffer containing binary data
00109  *\li   'length' is an integer
00110  *
00111  * Ensures:
00112  *\li   target will contain the data represented by the base32 encoded
00113  *      string parsed by the lexer.  No more than length bytes will be read,
00114  *      if length is positive.  The 'used' pointer in target will be
00115  *      advanced as necessary.
00116  */
00117 
00118 isc_result_t
00119 isc_base32_decoderegion(isc_region_t *source, isc_buffer_t *target);
00120 isc_result_t
00121 isc_base32hex_decoderegion(isc_region_t *source, isc_buffer_t *target);
00122 isc_result_t
00123 isc_base32hexnp_decoderegion(isc_region_t *source, isc_buffer_t *target);
00124 /*!<
00125  * \brief Decode a packed (no white space permitted) region in
00126  * base32, base32hex or base32hex non-padded.
00127  *
00128  * Requires:
00129  *\li   'source' is a valid region.
00130  *\li   'target' is a valid buffer.
00131  *
00132  * Returns:
00133  *\li   #ISC_R_SUCCESS  -- the entire decoded representation of 'cstring'
00134  *                         fit in 'target'.
00135  *\li   #ISC_R_BADBASE32 -- 'source' is not a valid base32 encoding.
00136  */
00137 
00138 ISC_LANG_ENDDECLS
00139 
00140 #endif /* ISC_BASE32_H */

Generated on Tue Apr 28 17:41:04 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha