2023-01-01 18:07:18 +08:00
|
|
|
//
|
|
|
|
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
// Official repository: https://github.com/boostorg/beast
|
|
|
|
//
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2023-01-01 18:07:18 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <utility>
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "platform/PlatformMacros.h"
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2023-01-01 18:07:18 +08:00
|
|
|
namespace base64 {
|
|
|
|
|
|
|
|
AX_DLL
|
|
|
|
char const*
|
|
|
|
get_alphabet();
|
|
|
|
|
|
|
|
AX_DLL
|
|
|
|
signed char const*
|
|
|
|
get_inverse();
|
|
|
|
|
|
|
|
/// Returns max chars needed to encode a base64 string
|
|
|
|
inline
|
|
|
|
std::size_t constexpr
|
|
|
|
encoded_size(std::size_t n)
|
|
|
|
{
|
|
|
|
return 4 * ((n + 2) / 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns max bytes needed to decode a base64 string
|
|
|
|
inline
|
|
|
|
std::size_t constexpr
|
|
|
|
decoded_size(std::size_t n)
|
|
|
|
{
|
|
|
|
return n / 4 * 3; // requires n&3==0, smaller
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Encode a series of octets as a padded, base64 string.
|
|
|
|
|
|
|
|
The resulting string will not be null terminated.
|
|
|
|
|
|
|
|
@par Requires
|
|
|
|
|
|
|
|
The memory pointed to by `out` points to valid memory
|
|
|
|
of at least `encoded_size(len)` bytes.
|
|
|
|
|
|
|
|
@return The number of characters written to `out`. This
|
|
|
|
will exclude any null termination.
|
|
|
|
*/
|
|
|
|
AX_DLL
|
|
|
|
std::size_t
|
|
|
|
encode(void* dest, void const* src, std::size_t len);
|
|
|
|
|
|
|
|
/** Decode a padded base64 string into a series of octets.
|
|
|
|
|
|
|
|
@par Requires
|
|
|
|
|
|
|
|
The memory pointed to by `out` points to valid memory
|
|
|
|
of at least `decoded_size(len)` bytes.
|
|
|
|
|
|
|
|
@return The number of octets written to `out`.
|
|
|
|
*/
|
|
|
|
AX_DLL
|
|
|
|
std::size_t decode(void* dest, char const* src, std::size_t len);
|
|
|
|
|
|
|
|
} // base64
|
|
|
|
|
|
|
|
NS_AX_END
|