"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/isc/include/isc/base32.h" (4 Sep 2020, 4452 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "base32.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 #ifndef ISC_BASE32_H
   13 #define ISC_BASE32_H 1
   14 
   15 /*! \file */
   16 
   17 /*
   18  * Routines for manipulating base 32 and base 32 hex encoded data.
   19  * Based on RFC 4648.
   20  *
   21  * Base 32 hex preserves the sort order of data when it is encoded /
   22  * decoded.
   23  *
   24  * Base 32 hex "np" is base 32 hex but no padding is produced or accepted.
   25  */
   26 
   27 #include <isc/lang.h>
   28 #include <isc/types.h>
   29 
   30 ISC_LANG_BEGINDECLS
   31 
   32 /***
   33  *** Functions
   34  ***/
   35 
   36 isc_result_t
   37 isc_base32_totext(isc_region_t *source, int wordlength, const char *wordbreak,
   38           isc_buffer_t *target);
   39 isc_result_t
   40 isc_base32hex_totext(isc_region_t *source, int wordlength,
   41              const char *wordbreak, isc_buffer_t *target);
   42 isc_result_t
   43 isc_base32hexnp_totext(isc_region_t *source, int wordlength,
   44                const char *wordbreak, isc_buffer_t *target);
   45 /*!<
   46  * \brief Convert data into base32 encoded text.
   47  *
   48  * Notes:
   49  *\li   The base32 encoded text in 'target' will be divided into
   50  *  words of at most 'wordlength' characters, separated by
   51  *  the 'wordbreak' string.  No parentheses will surround
   52  *  the text.
   53  *
   54  * Requires:
   55  *\li   'source' is a region containing binary data
   56  *\li   'target' is a text buffer containing available space
   57  *\li   'wordbreak' points to a null-terminated string of
   58  *      zero or more whitespace characters
   59  *
   60  * Ensures:
   61  *\li   target will contain the base32 encoded version of the data
   62  *  in source.  The 'used' pointer in target will be advanced as
   63  *  necessary.
   64  */
   65 
   66 isc_result_t
   67 isc_base32_decodestring(const char *cstr, isc_buffer_t *target);
   68 isc_result_t
   69 isc_base32hex_decodestring(const char *cstr, isc_buffer_t *target);
   70 isc_result_t
   71 isc_base32hexnp_decodestring(const char *cstr, isc_buffer_t *target);
   72 /*!<
   73  * \brief Decode a null-terminated string in base32, base32hex, or
   74  * base32hex non-padded.
   75  *
   76  * Requires:
   77  *\li   'cstr' is non-null.
   78  *\li   'target' is a valid buffer.
   79  *
   80  * Returns:
   81  *\li   #ISC_R_SUCCESS  -- the entire decoded representation of 'cstring'
   82  *             fit in 'target'.
   83  *\li   #ISC_R_BADBASE32 -- 'cstr' is not a valid base32 encoding.
   84  *
   85  *  Other error returns are any possible error code from:
   86  *\li       isc_lex_create(),
   87  *\li       isc_lex_openbuffer(),
   88  *\li       isc_base32_tobuffer().
   89  */
   90 
   91 isc_result_t
   92 isc_base32_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
   93 isc_result_t
   94 isc_base32hex_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
   95 isc_result_t
   96 isc_base32hexnp_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
   97 /*!<
   98  * \brief Convert text encoded in base32, base32hex, or base32hex
   99  * non-padded from a lexer context into `target`. If 'length' is
  100  * non-negative, it is the expected number of encoded octets to convert.
  101  *
  102  * If 'length' is -1 then 0 or more encoded octets are expected.
  103  * If 'length' is -2 then 1 or more encoded octets are expected.
  104  *
  105  * Returns:
  106  *\li   #ISC_R_BADBASE32 -- invalid base32 encoding.
  107  *\li   #ISC_R_UNEXPECTEDEND: the text does not contain the expected
  108  *                number of encoded octets.
  109  *
  110  * Requires:
  111  *\li   'lexer' is a valid lexer context
  112  *\li   'target' is a buffer containing binary data
  113  *\li   'length' is -2, -1, or non-negative
  114  *
  115  * Ensures:
  116  *\li   target will contain the data represented by the base32 encoded
  117  *  string parsed by the lexer.  No more than `length` octets will
  118  *  be read, if `length` is non-negative.  The 'used' pointer in
  119  *  'target' will be advanced as necessary.
  120  */
  121 
  122 isc_result_t
  123 isc_base32_decoderegion(isc_region_t *source, isc_buffer_t *target);
  124 isc_result_t
  125 isc_base32hex_decoderegion(isc_region_t *source, isc_buffer_t *target);
  126 isc_result_t
  127 isc_base32hexnp_decoderegion(isc_region_t *source, isc_buffer_t *target);
  128 /*!<
  129  * \brief Decode a packed (no white space permitted) region in
  130  * base32, base32hex or base32hex non-padded.
  131  *
  132  * Requires:
  133  *\li   'source' is a valid region.
  134  *\li   'target' is a valid buffer.
  135  *
  136  * Returns:
  137  *\li   #ISC_R_SUCCESS  -- the entire decoded representation of 'cstring'
  138  *                         fit in 'target'.
  139  *\li   #ISC_R_BADBASE32 -- 'source' is not a valid base32 encoding.
  140  */
  141 
  142 ISC_LANG_ENDDECLS
  143 
  144 #endif /* ISC_BASE32_H */