blob: fb0d753a2e252dd91cfc8942c5b8145defdf2ced [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 *
Paul Bakker84f12b72010-07-18 10:13:04 +00006 * Copyright (C) 2006-2010, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +000010 *
Paul Bakker77b385e2009-07-28 17:23:11 +000011 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000012 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000013 * 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 Bakker5121ce52009-01-03 21:22:43 +000026 */
Paul Bakker40e46942009-01-03 21:51:57 +000027#ifndef POLARSSL_BASE64_H
28#define POLARSSL_BASE64_H
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Paul Bakker23986e52011-04-24 08:57:21 +000030#include <string.h>
31
Paul Bakker69e095c2011-12-10 21:55:01 +000032#define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */
33#define POLARSSL_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */
Paul Bakker5121ce52009-01-03 21:22:43 +000034
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/**
40 * \brief Encode a buffer into base64 format
41 *
42 * \param dst destination buffer
43 * \param dlen size of the buffer
44 * \param src source buffer
45 * \param slen amount of data to be encoded
46 *
Paul Bakker40e46942009-01-03 21:51:57 +000047 * \return 0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL.
Paul Bakker5121ce52009-01-03 21:22:43 +000048 * *dlen is always updated to reflect the amount
49 * of data that has (or would have) been written.
50 *
51 * \note Call this function with *dlen = 0 to obtain the
52 * required buffer size in *dlen
53 */
Paul Bakker23986e52011-04-24 08:57:21 +000054int base64_encode( unsigned char *dst, size_t *dlen,
55 const unsigned char *src, size_t slen );
Paul Bakker5121ce52009-01-03 21:22:43 +000056
57/**
58 * \brief Decode a base64-formatted buffer
59 *
60 * \param dst destination buffer
61 * \param dlen size of the buffer
62 * \param src source buffer
63 * \param slen amount of data to be decoded
64 *
Paul Bakker40e46942009-01-03 21:51:57 +000065 * \return 0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or
Paul Bakkerfbb5cf92013-02-14 11:56:58 +010066 * POLARSSL_ERR_BASE64_INVALID_CHARACTER if the input data is
67 * not correct. *dlen is always updated to reflect the amount
Paul Bakker5121ce52009-01-03 21:22:43 +000068 * of data that has (or would have) been written.
69 *
70 * \note Call this function with *dlen = 0 to obtain the
71 * required buffer size in *dlen
72 */
Paul Bakker23986e52011-04-24 08:57:21 +000073int base64_decode( unsigned char *dst, size_t *dlen,
74 const unsigned char *src, size_t slen );
Paul Bakker5121ce52009-01-03 21:22:43 +000075
76/**
77 * \brief Checkup routine
78 *
79 * \return 0 if successful, or 1 if the test failed
80 */
81int base64_self_test( int verbose );
82
83#ifdef __cplusplus
84}
85#endif
86
87#endif /* base64.h */