Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:24

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_DETAIL_BASE64_HPP
0011 #define BOOST_BEAST_DETAIL_BASE64_HPP
0012 
0013 #include <boost/beast/core/string.hpp>
0014 #include <cctype>
0015 #include <utility>
0016 
0017 namespace boost {
0018 namespace beast {
0019 namespace detail {
0020 
0021 namespace base64 {
0022 
0023 BOOST_BEAST_DECL
0024 char const*
0025 get_alphabet();
0026 
0027 BOOST_BEAST_DECL
0028 signed char const*
0029 get_inverse();
0030 
0031 /// Returns max chars needed to encode a base64 string
0032 BOOST_BEAST_DECL
0033 std::size_t constexpr
0034 encoded_size(std::size_t n)
0035 {
0036     return 4 * ((n + 2) / 3);
0037 }
0038 
0039 /// Returns max bytes needed to decode a base64 string
0040 inline
0041 std::size_t constexpr
0042 decoded_size(std::size_t n)
0043 {
0044     return n / 4 * 3; // requires n&3==0, smaller
0045 }
0046 
0047 /** Encode a series of octets as a padded, base64 string.
0048 
0049     The resulting string will not be null terminated.
0050 
0051     @par Requires
0052 
0053     The memory pointed to by `out` points to valid memory
0054     of at least `encoded_size(len)` bytes.
0055 
0056     @return The number of characters written to `out`. This
0057     will exclude any null termination.
0058 */
0059 BOOST_BEAST_DECL
0060 std::size_t
0061 encode(void* dest, void const* src, std::size_t len);
0062 
0063 /** Decode a padded base64 string into a series of octets.
0064 
0065     @par Requires
0066 
0067     The memory pointed to by `out` points to valid memory
0068     of at least `decoded_size(len)` bytes.
0069 
0070     @return The number of octets written to `out`, and
0071     the number of characters read from the input string,
0072     expressed as a pair.
0073 */
0074 BOOST_BEAST_DECL
0075 std::pair<std::size_t, std::size_t>
0076 decode(void* dest, char const* src, std::size_t len);
0077 
0078 } // base64
0079 
0080 } // detail
0081 } // beast
0082 } // boost
0083 
0084 #ifdef BOOST_BEAST_HEADER_ONLY
0085 #include <boost/beast/core/detail/base64.ipp>
0086 #endif
0087 
0088 #endif