1258945Sroberto/* 2258945Sroberto * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC") 3258945Sroberto * Copyright (C) 1999-2001 Internet Software Consortium. 4258945Sroberto * 5258945Sroberto * Permission to use, copy, modify, and/or distribute this software for any 6258945Sroberto * purpose with or without fee is hereby granted, provided that the above 7258945Sroberto * copyright notice and this permission notice appear in all copies. 8258945Sroberto * 9258945Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10258945Sroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11258945Sroberto * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12258945Sroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13258945Sroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14258945Sroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15258945Sroberto * PERFORMANCE OF THIS SOFTWARE. 16258945Sroberto */ 17258945Sroberto 18258945Sroberto/* $Id: base64.h,v 1.22 2007/06/19 23:47:18 tbox Exp $ */ 19258945Sroberto 20258945Sroberto#ifndef ISC_BASE64_H 21258945Sroberto#define ISC_BASE64_H 1 22258945Sroberto 23258945Sroberto/*! \file isc/base64.h */ 24258945Sroberto 25258945Sroberto#include <isc/lang.h> 26258945Sroberto#include <isc/types.h> 27258945Sroberto 28258945SrobertoISC_LANG_BEGINDECLS 29258945Sroberto 30258945Sroberto/*** 31258945Sroberto *** Functions 32258945Sroberto ***/ 33258945Sroberto 34258945Srobertoisc_result_t 35258945Srobertoisc_base64_totext(isc_region_t *source, int wordlength, 36258945Sroberto const char *wordbreak, isc_buffer_t *target); 37258945Sroberto/*!< 38258945Sroberto * \brief Convert data into base64 encoded text. 39258945Sroberto * 40258945Sroberto * Notes: 41258945Sroberto *\li The base64 encoded text in 'target' will be divided into 42258945Sroberto * words of at most 'wordlength' characters, separated by 43258945Sroberto * the 'wordbreak' string. No parentheses will surround 44258945Sroberto * the text. 45258945Sroberto * 46258945Sroberto * Requires: 47258945Sroberto *\li 'source' is a region containing binary data 48258945Sroberto *\li 'target' is a text buffer containing available space 49258945Sroberto *\li 'wordbreak' points to a null-terminated string of 50258945Sroberto * zero or more whitespace characters 51258945Sroberto * 52258945Sroberto * Ensures: 53258945Sroberto *\li target will contain the base64 encoded version of the data 54258945Sroberto * in source. The 'used' pointer in target will be advanced as 55258945Sroberto * necessary. 56258945Sroberto */ 57258945Sroberto 58258945Srobertoisc_result_t 59258945Srobertoisc_base64_decodestring(const char *cstr, isc_buffer_t *target); 60258945Sroberto/*!< 61258945Sroberto * \brief Decode a null-terminated base64 string. 62258945Sroberto * 63258945Sroberto * Requires: 64258945Sroberto *\li 'cstr' is non-null. 65258945Sroberto *\li 'target' is a valid buffer. 66258945Sroberto * 67258945Sroberto * Returns: 68258945Sroberto *\li #ISC_R_SUCCESS -- the entire decoded representation of 'cstring' 69258945Sroberto * fit in 'target'. 70258945Sroberto *\li #ISC_R_BADBASE64 -- 'cstr' is not a valid base64 encoding. 71258945Sroberto * 72258945Sroberto * Other error returns are any possible error code from: 73258945Sroberto *\li isc_lex_create(), 74258945Sroberto *\li isc_lex_openbuffer(), 75258945Sroberto *\li isc_base64_tobuffer(). 76258945Sroberto */ 77258945Sroberto 78258945Srobertoisc_result_t 79258945Srobertoisc_base64_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length); 80258945Sroberto/*!< 81258945Sroberto * \brief Convert base64 encoded text from a lexer context into data. 82258945Sroberto * 83258945Sroberto * Requires: 84258945Sroberto *\li 'lex' is a valid lexer context 85258945Sroberto *\li 'target' is a buffer containing binary data 86258945Sroberto *\li 'length' is an integer 87258945Sroberto * 88258945Sroberto * Ensures: 89258945Sroberto *\li target will contain the data represented by the base64 encoded 90258945Sroberto * string parsed by the lexer. No more than length bytes will be read, 91258945Sroberto * if length is positive. The 'used' pointer in target will be 92258945Sroberto * advanced as necessary. 93258945Sroberto */ 94258945Sroberto 95258945Sroberto 96258945Sroberto 97258945SrobertoISC_LANG_ENDDECLS 98258945Sroberto 99258945Sroberto#endif /* ISC_BASE64_H */ 100