blob: a6c97206025d64eb73975ccd08e16c5ac69f32a3 [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.
Harald Weltec7572392021-09-17 08:23:09 +020019 */
Harald Welte292f9e72021-09-17 08:35:32 +020020#pragma once
Harald Weltec7572392021-09-17 08:23:09 +020021
22#include <stddef.h>
23
Harald Weltec7572392021-09-17 08:23:09 +020024#ifdef __cplusplus
25extern "C" {
26#endif
27
28/**
29 * \brief Encode a buffer into base64 format
30 *
31 * \param dst destination buffer
32 * \param dlen size of the destination buffer
33 * \param olen number of bytes written
34 * \param src source buffer
35 * \param slen amount of data to be encoded
36 *
37 * \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL.
38 * *olen is always updated to reflect the amount
39 * of data that has (or would have) been written.
40 *
41 * \note Call this function with dlen = 0 to obtain the
42 * required buffer size in *olen
43 */
Harald Welted075e3a2021-09-17 08:45:25 +020044int osmo_base64_encode(unsigned char *dst, size_t dlen, size_t *olen,
45 const unsigned char *src, size_t slen);
Harald Weltec7572392021-09-17 08:23:09 +020046
47/**
48 * \brief Decode a base64-formatted buffer
49 *
50 * \param dst destination buffer (can be NULL for checking size)
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 decoded
55 *
56 * \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or
57 * MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is
58 * not correct. *olen is always updated to reflect the amount
59 * of data that has (or would have) been written.
60 *
61 * \note Call this function with *dst = NULL or dlen = 0 to obtain
62 * the required buffer size in *olen
63 */
Harald Welted075e3a2021-09-17 08:45:25 +020064int osmo_base64_decode(unsigned char *dst, size_t dlen, size_t *olen,
65 const unsigned char *src, size_t slen);
Harald Weltec7572392021-09-17 08:23:09 +020066
Harald Weltec7572392021-09-17 08:23:09 +020067#ifdef __cplusplus
68}
69#endif