blob: bb1c236d300b2c072fd4a6af8913f6ac30c60074 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file base64.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakkerfc8c4362010-03-21 17:37:16 +00004 * Copyright (C) 2006-2010, Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakker77b385e2009-07-28 17:23:11 +00005 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00006 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000020 */
Paul Bakker40e46942009-01-03 21:51:57 +000021#ifndef POLARSSL_BASE64_H
22#define POLARSSL_BASE64_H
Paul Bakker5121ce52009-01-03 21:22:43 +000023
Paul Bakkerb5bf1762009-07-19 20:28:35 +000024#define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL 0x0010
25#define POLARSSL_ERR_BASE64_INVALID_CHARACTER 0x0012
Paul Bakker5121ce52009-01-03 21:22:43 +000026
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 * \brief Encode a buffer into base64 format
33 *
34 * \param dst destination buffer
35 * \param dlen size of the buffer
36 * \param src source buffer
37 * \param slen amount of data to be encoded
38 *
Paul Bakker40e46942009-01-03 21:51:57 +000039 * \return 0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL.
Paul Bakker5121ce52009-01-03 21:22:43 +000040 * *dlen is always updated to reflect the amount
41 * of data that has (or would have) been written.
42 *
43 * \note Call this function with *dlen = 0 to obtain the
44 * required buffer size in *dlen
45 */
46int base64_encode( unsigned char *dst, int *dlen,
Paul Bakkerff60ee62010-03-16 21:09:09 +000047 const unsigned char *src, int slen );
Paul Bakker5121ce52009-01-03 21:22:43 +000048
49/**
50 * \brief Decode a base64-formatted buffer
51 *
52 * \param dst destination buffer
53 * \param dlen size of the buffer
54 * \param src source buffer
55 * \param slen amount of data to be decoded
56 *
Paul Bakker40e46942009-01-03 21:51:57 +000057 * \return 0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or
58 * POLARSSL_ERR_BASE64_INVALID_DATA if the input data is not
Paul Bakker5121ce52009-01-03 21:22:43 +000059 * correct. *dlen is always updated to reflect the amount
60 * of data that has (or would have) been written.
61 *
62 * \note Call this function with *dlen = 0 to obtain the
63 * required buffer size in *dlen
64 */
65int base64_decode( unsigned char *dst, int *dlen,
Paul Bakkerff60ee62010-03-16 21:09:09 +000066 const unsigned char *src, int slen );
Paul Bakker5121ce52009-01-03 21:22:43 +000067
68/**
69 * \brief Checkup routine
70 *
71 * \return 0 if successful, or 1 if the test failed
72 */
73int base64_self_test( int verbose );
74
75#ifdef __cplusplus
76}
77#endif
78
79#endif /* base64.h */