mbed TLS library

Dependents:   HTTPClient-SSL WS_SERVER

Committer:
ansond
Date:
Thu Jun 11 03:27:03 2015 +0000
Revision:
0:137634ff4186
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:137634ff4186 1 /**
ansond 0:137634ff4186 2 * \file base64.h
ansond 0:137634ff4186 3 *
ansond 0:137634ff4186 4 * \brief RFC 1521 base64 encoding/decoding
ansond 0:137634ff4186 5 *
ansond 0:137634ff4186 6 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
ansond 0:137634ff4186 7 *
ansond 0:137634ff4186 8 * This file is part of mbed TLS (https://tls.mbed.org)
ansond 0:137634ff4186 9 *
ansond 0:137634ff4186 10 * This program is free software; you can redistribute it and/or modify
ansond 0:137634ff4186 11 * it under the terms of the GNU General Public License as published by
ansond 0:137634ff4186 12 * the Free Software Foundation; either version 2 of the License, or
ansond 0:137634ff4186 13 * (at your option) any later version.
ansond 0:137634ff4186 14 *
ansond 0:137634ff4186 15 * This program is distributed in the hope that it will be useful,
ansond 0:137634ff4186 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ansond 0:137634ff4186 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ansond 0:137634ff4186 18 * GNU General Public License for more details.
ansond 0:137634ff4186 19 *
ansond 0:137634ff4186 20 * You should have received a copy of the GNU General Public License along
ansond 0:137634ff4186 21 * with this program; if not, write to the Free Software Foundation, Inc.,
ansond 0:137634ff4186 22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ansond 0:137634ff4186 23 */
ansond 0:137634ff4186 24 #ifndef POLARSSL_BASE64_H
ansond 0:137634ff4186 25 #define POLARSSL_BASE64_H
ansond 0:137634ff4186 26
ansond 0:137634ff4186 27 #include <stddef.h>
ansond 0:137634ff4186 28
ansond 0:137634ff4186 29 #define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */
ansond 0:137634ff4186 30 #define POLARSSL_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */
ansond 0:137634ff4186 31
ansond 0:137634ff4186 32 #ifdef __cplusplus
ansond 0:137634ff4186 33 extern "C" {
ansond 0:137634ff4186 34 #endif
ansond 0:137634ff4186 35
ansond 0:137634ff4186 36 /**
ansond 0:137634ff4186 37 * \brief Encode a buffer into base64 format
ansond 0:137634ff4186 38 *
ansond 0:137634ff4186 39 * \param dst destination buffer
ansond 0:137634ff4186 40 * \param dlen size of the buffer
ansond 0:137634ff4186 41 * \param src source buffer
ansond 0:137634ff4186 42 * \param slen amount of data to be encoded
ansond 0:137634ff4186 43 *
ansond 0:137634ff4186 44 * \return 0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL.
ansond 0:137634ff4186 45 * *dlen is always updated to reflect the amount
ansond 0:137634ff4186 46 * of data that has (or would have) been written.
ansond 0:137634ff4186 47 *
ansond 0:137634ff4186 48 * \note Call this function with *dlen = 0 to obtain the
ansond 0:137634ff4186 49 * required buffer size in *dlen
ansond 0:137634ff4186 50 */
ansond 0:137634ff4186 51 int base64_encode( unsigned char *dst, size_t *dlen,
ansond 0:137634ff4186 52 const unsigned char *src, size_t slen );
ansond 0:137634ff4186 53
ansond 0:137634ff4186 54 /**
ansond 0:137634ff4186 55 * \brief Decode a base64-formatted buffer
ansond 0:137634ff4186 56 *
ansond 0:137634ff4186 57 * \param dst destination buffer (can be NULL for checking size)
ansond 0:137634ff4186 58 * \param dlen size of the buffer
ansond 0:137634ff4186 59 * \param src source buffer
ansond 0:137634ff4186 60 * \param slen amount of data to be decoded
ansond 0:137634ff4186 61 *
ansond 0:137634ff4186 62 * \return 0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or
ansond 0:137634ff4186 63 * POLARSSL_ERR_BASE64_INVALID_CHARACTER if the input data is
ansond 0:137634ff4186 64 * not correct. *dlen is always updated to reflect the amount
ansond 0:137634ff4186 65 * of data that has (or would have) been written.
ansond 0:137634ff4186 66 *
ansond 0:137634ff4186 67 * \note Call this function with *dst = NULL or *dlen = 0 to obtain
ansond 0:137634ff4186 68 * the required buffer size in *dlen
ansond 0:137634ff4186 69 */
ansond 0:137634ff4186 70 int base64_decode( unsigned char *dst, size_t *dlen,
ansond 0:137634ff4186 71 const unsigned char *src, size_t slen );
ansond 0:137634ff4186 72
ansond 0:137634ff4186 73 /**
ansond 0:137634ff4186 74 * \brief Checkup routine
ansond 0:137634ff4186 75 *
ansond 0:137634ff4186 76 * \return 0 if successful, or 1 if the test failed
ansond 0:137634ff4186 77 */
ansond 0:137634ff4186 78 int base64_self_test( int verbose );
ansond 0:137634ff4186 79
ansond 0:137634ff4186 80 #ifdef __cplusplus
ansond 0:137634ff4186 81 }
ansond 0:137634ff4186 82 #endif
ansond 0:137634ff4186 83
ansond 0:137634ff4186 84 #endif /* base64.h */
ansond 0:137634ff4186 85