Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file base64.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
| 4 | * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine |
| 5 | * |
| 6 | * Copyright (C) 2009 Paul Bakker |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 21 | */ |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 22 | #ifndef POLARSSL_BASE64_H |
| 23 | #define POLARSSL_BASE64_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 24 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 25 | #define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x0010 |
| 26 | #define POLARSSL_ERR_BASE64_INVALID_CHARACTER -0x0012 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 27 | |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 | |
| 32 | /** |
| 33 | * \brief Encode a buffer into base64 format |
| 34 | * |
| 35 | * \param dst destination buffer |
| 36 | * \param dlen size of the buffer |
| 37 | * \param src source buffer |
| 38 | * \param slen amount of data to be encoded |
| 39 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 40 | * \return 0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 41 | * *dlen is always updated to reflect the amount |
| 42 | * of data that has (or would have) been written. |
| 43 | * |
| 44 | * \note Call this function with *dlen = 0 to obtain the |
| 45 | * required buffer size in *dlen |
| 46 | */ |
| 47 | int base64_encode( unsigned char *dst, int *dlen, |
| 48 | unsigned char *src, int slen ); |
| 49 | |
| 50 | /** |
| 51 | * \brief Decode a base64-formatted buffer |
| 52 | * |
| 53 | * \param dst destination buffer |
| 54 | * \param dlen size of the buffer |
| 55 | * \param src source buffer |
| 56 | * \param slen amount of data to be decoded |
| 57 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 58 | * \return 0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or |
| 59 | * POLARSSL_ERR_BASE64_INVALID_DATA if the input data is not |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 60 | * correct. *dlen is always updated to reflect the amount |
| 61 | * of data that has (or would have) been written. |
| 62 | * |
| 63 | * \note Call this function with *dlen = 0 to obtain the |
| 64 | * required buffer size in *dlen |
| 65 | */ |
| 66 | int base64_decode( unsigned char *dst, int *dlen, |
| 67 | unsigned char *src, int slen ); |
| 68 | |
| 69 | /** |
| 70 | * \brief Checkup routine |
| 71 | * |
| 72 | * \return 0 if successful, or 1 if the test failed |
| 73 | */ |
| 74 | int base64_self_test( int verbose ); |
| 75 | |
| 76 | #ifdef __cplusplus |
| 77 | } |
| 78 | #endif |
| 79 | |
| 80 | #endif /* base64.h */ |