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