1 /* 2 * Copyright (c) 2000, 2002 X-Way Rights BV 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * 18 */ 19 20 /*!\file base64.h 21 * \brief Base64 encoding and decoding, headers. 22 * \author Bob Deblier <bob.deblier@telenet.be> 23 */ 24 25 #ifndef _BASE64_H 26 #define _BASE64_H 27 28 #include "beecrypt/beecrypt.h" 29 30 /*!\ 31 * Decode white space character set (default). 32 */ 33 extern const char* b64decode_whitespace; 34 #define B64DECODE_WHITESPACE " \f\n\r\t\v" 35 36 /*!\ 37 * Encode 72 characters per line (default). 38 */ 39 extern int b64encode_chars_per_line; 40 #define B64ENCODE_CHARS_PER_LINE 72 41 42 /*!\ 43 * Encode end-of-line string (default). 44 */ 45 extern const char* b64encode_eolstr; 46 #define B64ENCODE_EOLSTR "\n" 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 /*! 53 * Encode chunks of 3 bytes of binary input into 4 bytes of base64 output. 54 * \param data binary data 55 * \param ns no. bytes of data (0 uses strlen(data)) 56 * \return (malloc'd) base64 string 57 */ 58 BEECRYPTAPI 59 char* b64encode(const void* data, size_t ns); 60 61 /*! 62 * Encode crc of binary input data into 5 bytes of base64 output. 63 * \param data binary data 64 * \param ns no. bytes of binary data 65 * \return (malloc'd) base64 string 66 */ 67 BEECRYPTAPI 68 char* b64crc(const unsigned char* data, size_t ns); 69 70 /*! 71 * Decode chunks of 4 bytes of base64 input into 3 bytes of binary output. 72 * \param s base64 string 73 * \retval datap address of (malloc'd) binary data 74 * \retval lenp address of no. bytes of binary data 75 * \return 0 on success, 1: s == NULL, 2: bad length, 3: bad char 76 */ 77 BEECRYPTAPI 78 int b64decode(const char* s, void** datap, size_t* lenp); 79 80 /*! 81 */ 82 BEECRYPTAPI 83 char* b64enc(const memchunk*); 84 85 /*! 86 */ 87 BEECRYPTAPI 88 memchunk* b64dec(const char*); 89 90 #ifdef __cplusplus 91 } 92 #endif 93 94 #endif 95