Mbed OS Reference
Loading...
Searching...
No Matches
base64.h
Go to the documentation of this file.
1/**
2 * \file base64.h
3 *
4 * \brief RFC 1521 base64 encoding/decoding
5 */
6/*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22#ifndef MBEDTLS_BASE64_H
23#define MBEDTLS_BASE64_H
24
25#if !defined(MBEDTLS_CONFIG_FILE)
26#include "mbedtls/config.h"
27#else
28#include MBEDTLS_CONFIG_FILE
29#endif
30
31#include <stddef.h>
32
33/**
34 * \addtogroup mbedtls
35 * \{
36 * \defgroup mbedtls_base64_module Base64
37 * \{
38 */
39
40#define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */
41#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/**
48 * \brief Encode a buffer into base64 format
49 *
50 * \param dst destination buffer
51 * \param dlen size of the destination buffer
52 * \param olen number of bytes written
53 * \param src source buffer
54 * \param slen amount of data to be encoded
55 *
56 * \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL.
57 * *olen is always updated to reflect the amount
58 * of data that has (or would have) been written.
59 * If that length cannot be represented, then no data is
60 * written to the buffer and *olen is set to the maximum
61 * length representable as a size_t.
62 *
63 * \note Call this function with dlen = 0 to obtain the
64 * required buffer size in *olen
65 */
66int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
67 const unsigned char *src, size_t slen );
68
69/**
70 * \brief Decode a base64-formatted buffer
71 *
72 * \param dst destination buffer (can be NULL for checking size)
73 * \param dlen size of the destination buffer
74 * \param olen number of bytes written
75 * \param src source buffer
76 * \param slen amount of data to be decoded
77 *
78 * \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or
79 * MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is
80 * not correct. *olen is always updated to reflect the amount
81 * of data that has (or would have) been written.
82 *
83 * \note Call this function with *dst = NULL or dlen = 0 to obtain
84 * the required buffer size in *olen
85 */
86int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
87 const unsigned char *src, size_t slen );
88
89/// \}
90/// \}
91
92#if defined(MBEDTLS_SELF_TEST)
93/**
94 * \brief Checkup routine
95 *
96 * \return 0 if successful, or 1 if the test failed
97 */
98int mbedtls_base64_self_test( int verbose );
99
100#endif /* MBEDTLS_SELF_TEST */
101
102#ifdef __cplusplus
103}
104#endif
105
106#endif /* base64.h */
Configuration options (set of defines)
int mbedtls_base64_decode(unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen)
Decode a base64-formatted buffer.
int mbedtls_base64_encode(unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen)
Encode a buffer into base64 format.