Harald Welte | c757239 | 2021-09-17 08:23:09 +0200 | [diff] [blame] | 1 | /** |
| 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 Welte | 292f9e7 | 2021-09-17 08:35:32 +0200 | [diff] [blame] | 24 | #pragma once |
Harald Welte | c757239 | 2021-09-17 08:23:09 +0200 | [diff] [blame] | 25 | |
| 26 | #include <stddef.h> |
| 27 | |
Harald Welte | c757239 | 2021-09-17 08:23:09 +0200 | [diff] [blame] | 28 | #ifdef __cplusplus |
| 29 | extern "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 Welte | d075e3a | 2021-09-17 08:45:25 +0200 | [diff] [blame] | 48 | int osmo_base64_encode(unsigned char *dst, size_t dlen, size_t *olen, |
| 49 | const unsigned char *src, size_t slen); |
Harald Welte | c757239 | 2021-09-17 08:23:09 +0200 | [diff] [blame] | 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 Welte | d075e3a | 2021-09-17 08:45:25 +0200 | [diff] [blame] | 68 | int osmo_base64_decode(unsigned char *dst, size_t dlen, size_t *olen, |
| 69 | const unsigned char *src, size_t slen); |
Harald Welte | c757239 | 2021-09-17 08:23:09 +0200 | [diff] [blame] | 70 | |
Harald Welte | c757239 | 2021-09-17 08:23:09 +0200 | [diff] [blame] | 71 | #ifdef __cplusplus |
| 72 | } |
| 73 | #endif |