Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers base64.h Source File

base64.h

Go to the documentation of this file.
00001 /**
00002  * \file base64.h
00003  *
00004  * \brief RFC 1521 base64 encoding/decoding
00005  */
00006 /*
00007  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
00008  *  SPDX-License-Identifier: Apache-2.0
00009  *
00010  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00011  *  not use this file except in compliance with the License.
00012  *  You may obtain a copy of the License at
00013  *
00014  *  http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  *  Unless required by applicable law or agreed to in writing, software
00017  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00018  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019  *  See the License for the specific language governing permissions and
00020  *  limitations under the License.
00021  *
00022  *  This file is part of mbed TLS (https://tls.mbed.org)
00023  */
00024 #ifndef MBEDTLS_BASE64_H
00025 #define MBEDTLS_BASE64_H
00026 
00027 #if !defined(MBEDTLS_CONFIG_FILE)
00028 #include "mbedtls/config.h"
00029 #else
00030 #include MBEDTLS_CONFIG_FILE
00031 #endif
00032 
00033 #include <stddef.h>
00034 
00035 #define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL               -0x002A  /**< Output buffer too small. */
00036 #define MBEDTLS_ERR_BASE64_INVALID_CHARACTER              -0x002C  /**< Invalid character in input. */
00037 
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041 
00042 /**
00043  * \brief          Encode a buffer into base64 format
00044  *
00045  * \param dst      destination buffer
00046  * \param dlen     size of the destination buffer
00047  * \param olen     number of bytes written
00048  * \param src      source buffer
00049  * \param slen     amount of data to be encoded
00050  *
00051  * \return         0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL.
00052  *                 *olen is always updated to reflect the amount
00053  *                 of data that has (or would have) been written.
00054  *                 If that length cannot be represented, then no data is
00055  *                 written to the buffer and *olen is set to the maximum
00056  *                 length representable as a size_t.
00057  *
00058  * \note           Call this function with dlen = 0 to obtain the
00059  *                 required buffer size in *olen
00060  */
00061 int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
00062                    const unsigned char *src, size_t slen );
00063 
00064 /**
00065  * \brief          Decode a base64-formatted buffer
00066  *
00067  * \param dst      destination buffer (can be NULL for checking size)
00068  * \param dlen     size of the destination buffer
00069  * \param olen     number of bytes written
00070  * \param src      source buffer
00071  * \param slen     amount of data to be decoded
00072  *
00073  * \return         0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or
00074  *                 MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is
00075  *                 not correct. *olen is always updated to reflect the amount
00076  *                 of data that has (or would have) been written.
00077  *
00078  * \note           Call this function with *dst = NULL or dlen = 0 to obtain
00079  *                 the required buffer size in *olen
00080  */
00081 int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
00082                    const unsigned char *src, size_t slen );
00083 
00084 #if defined(MBEDTLS_SELF_TEST)
00085 /**
00086  * \brief          Checkup routine
00087  *
00088  * \return         0 if successful, or 1 if the test failed
00089  */
00090 int mbedtls_base64_self_test( int verbose );
00091 
00092 #endif /* MBEDTLS_SELF_TEST */
00093 
00094 #ifdef __cplusplus
00095 }
00096 #endif
00097 
00098 #endif /* base64.h */