]>
Commit | Line | Data |
---|---|---|
b32b8144 | 1 | // |
92f5a8d4 | 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) |
b32b8144 FG |
3 | // |
4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | // | |
7 | // Official repository: https://github.com/boostorg/beast | |
8 | // | |
9 | ||
b32b8144 FG |
10 | #ifndef BOOST_BEAST_DETAIL_BASE64_HPP |
11 | #define BOOST_BEAST_DETAIL_BASE64_HPP | |
12 | ||
92f5a8d4 | 13 | #include <boost/beast/core/string.hpp> |
b32b8144 | 14 | #include <cctype> |
b32b8144 FG |
15 | #include <utility> |
16 | ||
17 | namespace boost { | |
18 | namespace beast { | |
19 | namespace detail { | |
20 | ||
21 | namespace base64 { | |
22 | ||
92f5a8d4 | 23 | BOOST_BEAST_DECL |
b32b8144 | 24 | char const* |
92f5a8d4 | 25 | get_alphabet(); |
b32b8144 | 26 | |
92f5a8d4 | 27 | BOOST_BEAST_DECL |
b32b8144 | 28 | signed char const* |
92f5a8d4 | 29 | get_inverse(); |
b32b8144 FG |
30 | |
31 | /// Returns max chars needed to encode a base64 string | |
92f5a8d4 | 32 | BOOST_BEAST_DECL |
b32b8144 FG |
33 | std::size_t constexpr |
34 | encoded_size(std::size_t n) | |
35 | { | |
36 | return 4 * ((n + 2) / 3); | |
37 | } | |
38 | ||
39 | /// Returns max bytes needed to decode a base64 string | |
40 | inline | |
41 | std::size_t constexpr | |
42 | decoded_size(std::size_t n) | |
43 | { | |
44 | return n / 4 * 3; // requires n&3==0, smaller | |
b32b8144 FG |
45 | } |
46 | ||
47 | /** Encode a series of octets as a padded, base64 string. | |
48 | ||
49 | The resulting string will not be null terminated. | |
50 | ||
51 | @par Requires | |
52 | ||
53 | The memory pointed to by `out` points to valid memory | |
54 | of at least `encoded_size(len)` bytes. | |
55 | ||
56 | @return The number of characters written to `out`. This | |
57 | will exclude any null termination. | |
58 | */ | |
92f5a8d4 | 59 | BOOST_BEAST_DECL |
b32b8144 | 60 | std::size_t |
92f5a8d4 | 61 | encode(void* dest, void const* src, std::size_t len); |
b32b8144 FG |
62 | |
63 | /** Decode a padded base64 string into a series of octets. | |
64 | ||
65 | @par Requires | |
66 | ||
67 | The memory pointed to by `out` points to valid memory | |
68 | of at least `decoded_size(len)` bytes. | |
69 | ||
70 | @return The number of octets written to `out`, and | |
71 | the number of characters read from the input string, | |
72 | expressed as a pair. | |
73 | */ | |
92f5a8d4 | 74 | BOOST_BEAST_DECL |
b32b8144 | 75 | std::pair<std::size_t, std::size_t> |
92f5a8d4 | 76 | decode(void* dest, char const* src, std::size_t len); |
b32b8144 FG |
77 | |
78 | } // base64 | |
79 | ||
b32b8144 FG |
80 | } // detail |
81 | } // beast | |
82 | } // boost | |
83 | ||
92f5a8d4 TL |
84 | #ifdef BOOST_BEAST_HEADER_ONLY |
85 | #include <boost/beast/core/detail/base64.ipp> | |
86 | #endif | |
87 | ||
b32b8144 | 88 | #endif |