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