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