blob: 2da935b9460e5b77dd90cd73ef4cebff6f1996d0 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file base64.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief RFC 1521 base64 encoding/decoding
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnard860b5162015-01-28 17:12:07 +00008 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +00009 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 * 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 Bakker5121ce52009-01-03 21:22:43 +000023 */
Paul Bakker40e46942009-01-03 21:51:57 +000024#ifndef POLARSSL_BASE64_H
25#define POLARSSL_BASE64_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Paul Bakker23986e52011-04-24 08:57:21 +000027#include <string.h>
28
Paul Bakker69e095c2011-12-10 21:55:01 +000029#define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */
30#define POLARSSL_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */
Paul Bakker5121ce52009-01-03 21:22:43 +000031
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/**
37 * \brief Encode a buffer into base64 format
38 *
39 * \param dst destination buffer
40 * \param dlen size of the buffer
41 * \param src source buffer
42 * \param slen amount of data to be encoded
43 *
Paul Bakker40e46942009-01-03 21:51:57 +000044 * \return 0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL.
Paul Bakker5121ce52009-01-03 21:22:43 +000045 * *dlen is always updated to reflect the amount
46 * of data that has (or would have) been written.
47 *
48 * \note Call this function with *dlen = 0 to obtain the
49 * required buffer size in *dlen
50 */
Paul Bakker23986e52011-04-24 08:57:21 +000051int base64_encode( unsigned char *dst, size_t *dlen,
52 const unsigned char *src, size_t slen );
Paul Bakker5121ce52009-01-03 21:22:43 +000053
54/**
55 * \brief Decode a base64-formatted buffer
56 *
Paul Bakkerf4a14272013-07-05 10:29:12 +020057 * \param dst destination buffer (can be NULL for checking size)
Paul Bakker5121ce52009-01-03 21:22:43 +000058 * \param dlen size of the buffer
59 * \param src source buffer
60 * \param slen amount of data to be decoded
61 *
Paul Bakker40e46942009-01-03 21:51:57 +000062 * \return 0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or
Paul Bakkerfbb5cf92013-02-14 11:56:58 +010063 * POLARSSL_ERR_BASE64_INVALID_CHARACTER if the input data is
64 * not correct. *dlen is always updated to reflect the amount
Paul Bakker5121ce52009-01-03 21:22:43 +000065 * of data that has (or would have) been written.
66 *
Paul Bakkerf4a14272013-07-05 10:29:12 +020067 * \note Call this function with *dst = NULL or *dlen = 0 to obtain
68 * the required buffer size in *dlen
Paul Bakker5121ce52009-01-03 21:22:43 +000069 */
Paul Bakker23986e52011-04-24 08:57:21 +000070int base64_decode( unsigned char *dst, size_t *dlen,
71 const unsigned char *src, size_t slen );
Paul Bakker5121ce52009-01-03 21:22:43 +000072
73/**
74 * \brief Checkup routine
75 *
76 * \return 0 if successful, or 1 if the test failed
77 */
78int base64_self_test( int verbose );
79
80#ifdef __cplusplus
81}
82#endif
83
84#endif /* base64.h */