Path: blob/master/thirdparty/mbedtls/include/mbedtls/base64.h
9903 views
/**1* \file base64.h2*3* \brief RFC 1521 base64 encoding/decoding4*/5/*6* Copyright The Mbed TLS Contributors7* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later8*/9#ifndef MBEDTLS_BASE64_H10#define MBEDTLS_BASE64_H1112#include "mbedtls/build_info.h"1314#include <stddef.h>1516/** Output buffer too small. */17#define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A18/** Invalid character in input. */19#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C2021#ifdef __cplusplus22extern "C" {23#endif2425/**26* \brief Encode a buffer into base64 format27*28* \param dst destination buffer29* \param dlen size of the destination buffer30* \param olen number of bytes written31* \param src source buffer32* \param slen amount of data to be encoded33*34* \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL.35* *olen is always updated to reflect the amount36* of data that has (or would have) been written.37* If that length cannot be represented, then no data is38* written to the buffer and *olen is set to the maximum39* length representable as a size_t.40*41* \note Call this function with dlen = 0 to obtain the42* required buffer size in *olen43*/44int mbedtls_base64_encode(unsigned char *dst, size_t dlen, size_t *olen,45const unsigned char *src, size_t slen);4647/**48* \brief Decode a base64-formatted buffer49*50* \param dst destination buffer (can be NULL for checking size)51* \param dlen size of the destination buffer52* \param olen number of bytes written53* \param src source buffer54* \param slen amount of data to be decoded55*56* \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or57* MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is58* not correct. *olen is always updated to reflect the amount59* of data that has (or would have) been written.60*61* \note Call this function with *dst = NULL or dlen = 0 to obtain62* the required buffer size in *olen63*/64int mbedtls_base64_decode(unsigned char *dst, size_t dlen, size_t *olen,65const unsigned char *src, size_t slen);6667#if defined(MBEDTLS_SELF_TEST)68/**69* \brief Checkup routine70*71* \return 0 if successful, or 1 if the test failed72*/73int mbedtls_base64_self_test(int verbose);7475#endif /* MBEDTLS_SELF_TEST */7677#ifdef __cplusplus78}79#endif8081#endif /* base64.h */828384