blob: 61754d15cd82c6376f7b105ca4e2ca9ab5439b52 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file base64.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
4 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
5 *
6 * Copyright (C) 2009 Paul Bakker
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000021 */
Paul Bakker40e46942009-01-03 21:51:57 +000022#ifndef POLARSSL_BASE64_H
23#define POLARSSL_BASE64_H
Paul Bakker5121ce52009-01-03 21:22:43 +000024
Paul Bakker40e46942009-01-03 21:51:57 +000025#define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x0010
26#define POLARSSL_ERR_BASE64_INVALID_CHARACTER -0x0012
Paul Bakker5121ce52009-01-03 21:22:43 +000027
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/**
33 * \brief Encode a buffer into base64 format
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 encoded
39 *
Paul Bakker40e46942009-01-03 21:51:57 +000040 * \return 0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL.
Paul Bakker5121ce52009-01-03 21:22:43 +000041 * *dlen is always updated to reflect the amount
42 * of data that has (or would have) been written.
43 *
44 * \note Call this function with *dlen = 0 to obtain the
45 * required buffer size in *dlen
46 */
47int base64_encode( unsigned char *dst, int *dlen,
48 unsigned char *src, int slen );
49
50/**
51 * \brief Decode a base64-formatted buffer
52 *
53 * \param dst destination buffer
54 * \param dlen size of the buffer
55 * \param src source buffer
56 * \param slen amount of data to be decoded
57 *
Paul Bakker40e46942009-01-03 21:51:57 +000058 * \return 0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or
59 * POLARSSL_ERR_BASE64_INVALID_DATA if the input data is not
Paul Bakker5121ce52009-01-03 21:22:43 +000060 * correct. *dlen is always updated to reflect the amount
61 * of data that has (or would have) been written.
62 *
63 * \note Call this function with *dlen = 0 to obtain the
64 * required buffer size in *dlen
65 */
66int base64_decode( unsigned char *dst, int *dlen,
67 unsigned char *src, int slen );
68
69/**
70 * \brief Checkup routine
71 *
72 * \return 0 if successful, or 1 if the test failed
73 */
74int base64_self_test( int verbose );
75
76#ifdef __cplusplus
77}
78#endif
79
80#endif /* base64.h */