blob: f73db0d80b74723b6c1dcee1cef43bf110759e14 [file] [log] [blame]
Harald Weltec7572392021-09-17 08:23:09 +02001/**
2 * \file base64.h
3 *
4 * \brief RFC 1521 base64 encoding/decoding
5 *
6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7 *
8 * This file is part of mbed TLS (https://tls.mbed.org)
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
Harald Welte292f9e72021-09-17 08:35:32 +020024#pragma once
Harald Weltec7572392021-09-17 08:23:09 +020025
26#include <stddef.h>
27
Harald Weltec7572392021-09-17 08:23:09 +020028#ifdef __cplusplus
29extern "C" {
30#endif
31
32/**
33 * \brief Encode a buffer into base64 format
34 *
35 * \param dst destination buffer
36 * \param dlen size of the destination buffer
37 * \param olen number of bytes written
38 * \param src source buffer
39 * \param slen amount of data to be encoded
40 *
41 * \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL.
42 * *olen 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 *olen
47 */
Harald Welte292f9e72021-09-17 08:35:32 +020048int osmo_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
Harald Weltec7572392021-09-17 08:23:09 +020049 const unsigned char *src, size_t slen );
50
51/**
52 * \brief Decode a base64-formatted buffer
53 *
54 * \param dst destination buffer (can be NULL for checking size)
55 * \param dlen size of the destination buffer
56 * \param olen number of bytes written
57 * \param src source buffer
58 * \param slen amount of data to be decoded
59 *
60 * \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or
61 * MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is
62 * not correct. *olen is always updated to reflect the amount
63 * of data that has (or would have) been written.
64 *
65 * \note Call this function with *dst = NULL or dlen = 0 to obtain
66 * the required buffer size in *olen
67 */
Harald Welte292f9e72021-09-17 08:35:32 +020068int osmo_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
Harald Weltec7572392021-09-17 08:23:09 +020069 const unsigned char *src, size_t slen );
70
Harald Weltec7572392021-09-17 08:23:09 +020071#ifdef __cplusplus
72}
73#endif