Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file base64.h |
| 3 | */ |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame^] | 4 | #ifndef POLARSSL_BASE64_H |
| 5 | #define POLARSSL_BASE64_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 6 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame^] | 7 | #define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x0010 |
| 8 | #define POLARSSL_ERR_BASE64_INVALID_CHARACTER -0x0012 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 9 | |
| 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
| 14 | /** |
| 15 | * \brief Encode a buffer into base64 format |
| 16 | * |
| 17 | * \param dst destination buffer |
| 18 | * \param dlen size of the buffer |
| 19 | * \param src source buffer |
| 20 | * \param slen amount of data to be encoded |
| 21 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame^] | 22 | * \return 0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 23 | * *dlen is always updated to reflect the amount |
| 24 | * of data that has (or would have) been written. |
| 25 | * |
| 26 | * \note Call this function with *dlen = 0 to obtain the |
| 27 | * required buffer size in *dlen |
| 28 | */ |
| 29 | int base64_encode( unsigned char *dst, int *dlen, |
| 30 | unsigned char *src, int slen ); |
| 31 | |
| 32 | /** |
| 33 | * \brief Decode a base64-formatted buffer |
| 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 decoded |
| 39 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame^] | 40 | * \return 0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or |
| 41 | * POLARSSL_ERR_BASE64_INVALID_DATA if the input data is not |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 42 | * correct. *dlen is always updated to reflect the amount |
| 43 | * of data that has (or would have) been written. |
| 44 | * |
| 45 | * \note Call this function with *dlen = 0 to obtain the |
| 46 | * required buffer size in *dlen |
| 47 | */ |
| 48 | int base64_decode( unsigned char *dst, int *dlen, |
| 49 | unsigned char *src, int slen ); |
| 50 | |
| 51 | /** |
| 52 | * \brief Checkup routine |
| 53 | * |
| 54 | * \return 0 if successful, or 1 if the test failed |
| 55 | */ |
| 56 | int base64_self_test( int verbose ); |
| 57 | |
| 58 | #ifdef __cplusplus |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | #endif /* base64.h */ |