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 | * |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame^] | 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 7 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 8 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 9 | * |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 23 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 24 | #ifndef MBEDTLS_BASE64_H |
| 25 | #define MBEDTLS_BASE64_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 26 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 27 | #include <stddef.h> |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 28 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 29 | #define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */ |
| 30 | #define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 31 | |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
| 36 | /** |
| 37 | * \brief Encode a buffer into base64 format |
| 38 | * |
| 39 | * \param dst destination buffer |
Manuel Pégourié-Gonnard | ba56136 | 2015-06-02 16:30:35 +0100 | [diff] [blame] | 40 | * \param dlen size of the destination buffer |
| 41 | * \param olen number of bytes written |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 42 | * \param src source buffer |
| 43 | * \param slen amount of data to be encoded |
| 44 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 45 | * \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL. |
Manuel Pégourié-Gonnard | ba56136 | 2015-06-02 16:30:35 +0100 | [diff] [blame] | 46 | * *olen is always updated to reflect the amount |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 47 | * of data that has (or would have) been written. |
| 48 | * |
Manuel Pégourié-Gonnard | ba56136 | 2015-06-02 16:30:35 +0100 | [diff] [blame] | 49 | * \note Call this function with dlen = 0 to obtain the |
| 50 | * required buffer size in *olen |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 51 | */ |
Manuel Pégourié-Gonnard | ba56136 | 2015-06-02 16:30:35 +0100 | [diff] [blame] | 52 | int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 53 | const unsigned char *src, size_t slen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * \brief Decode a base64-formatted buffer |
| 57 | * |
Paul Bakker | f4a1427 | 2013-07-05 10:29:12 +0200 | [diff] [blame] | 58 | * \param dst destination buffer (can be NULL for checking size) |
Manuel Pégourié-Gonnard | ba56136 | 2015-06-02 16:30:35 +0100 | [diff] [blame] | 59 | * \param dlen size of the destination buffer |
| 60 | * \param olen number of bytes written |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 61 | * \param src source buffer |
| 62 | * \param slen amount of data to be decoded |
| 63 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 64 | * \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or |
| 65 | * MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is |
Manuel Pégourié-Gonnard | ba56136 | 2015-06-02 16:30:35 +0100 | [diff] [blame] | 66 | * not correct. *olen is always updated to reflect the amount |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 67 | * of data that has (or would have) been written. |
| 68 | * |
Manuel Pégourié-Gonnard | ba56136 | 2015-06-02 16:30:35 +0100 | [diff] [blame] | 69 | * \note Call this function with *dst = NULL or dlen = 0 to obtain |
| 70 | * the required buffer size in *olen |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 71 | */ |
Manuel Pégourié-Gonnard | ba56136 | 2015-06-02 16:30:35 +0100 | [diff] [blame] | 72 | int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 73 | const unsigned char *src, size_t slen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * \brief Checkup routine |
| 77 | * |
| 78 | * \return 0 if successful, or 1 if the test failed |
| 79 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 80 | int mbedtls_base64_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 81 | |
| 82 | #ifdef __cplusplus |
| 83 | } |
| 84 | #endif |
| 85 | |
| 86 | #endif /* base64.h */ |