1 /* $NetBSD: base64.h,v 1.4 2014/12/10 04:38:00 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (C) 1999-2001 Internet Software Consortium. 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /* Id: base64.h,v 1.22 2007/06/19 23:47:18 tbox Exp */ 21 22 #ifndef ISC_BASE64_H 23 #define ISC_BASE64_H 1 24 25 /*! \file isc/base64.h */ 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_base64_totext(isc_region_t *source, int wordlength, 38 const char *wordbreak, isc_buffer_t *target); 39 /*!< 40 * \brief Convert data into base64 encoded text. 41 * 42 * Notes: 43 *\li The base64 encoded text in 'target' will be divided into 44 * words of at most 'wordlength' characters, separated by 45 * the 'wordbreak' string. No parentheses will surround 46 * the text. 47 * 48 * Requires: 49 *\li 'source' is a region containing binary data 50 *\li 'target' is a text buffer containing available space 51 *\li 'wordbreak' points to a null-terminated string of 52 * zero or more whitespace characters 53 * 54 * Ensures: 55 *\li target will contain the base64 encoded version of the data 56 * in source. The 'used' pointer in target will be advanced as 57 * necessary. 58 */ 59 60 isc_result_t 61 isc_base64_decodestring(const char *cstr, isc_buffer_t *target); 62 /*!< 63 * \brief Decode a null-terminated base64 string. 64 * 65 * Requires: 66 *\li 'cstr' is non-null. 67 *\li 'target' is a valid buffer. 68 * 69 * Returns: 70 *\li #ISC_R_SUCCESS -- the entire decoded representation of 'cstring' 71 * fit in 'target'. 72 *\li #ISC_R_BADBASE64 -- 'cstr' is not a valid base64 encoding. 73 * 74 * Other error returns are any possible error code from: 75 *\li isc_lex_create(), 76 *\li isc_lex_openbuffer(), 77 *\li isc_base64_tobuffer(). 78 */ 79 80 isc_result_t 81 isc_base64_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length); 82 /*!< 83 * \brief Convert base64 encoded text from a lexer context into data. 84 * 85 * Requires: 86 *\li 'lex' is a valid lexer context 87 *\li 'target' is a buffer containing binary data 88 *\li 'length' is an integer 89 * 90 * Ensures: 91 *\li target will contain the data represented by the base64 encoded 92 * string parsed by the lexer. No more than length bytes will be read, 93 * if length is positive. The 'used' pointer in target will be 94 * advanced as necessary. 95 */ 96 97 98 99 ISC_LANG_ENDDECLS 100 101 #endif /* ISC_BASE64_H */ 102