xrpld
Loading...
Searching...
No Matches
base64.h
1// Distributed under the Boost Software License, Version 1.0. (See accompanying
2// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
3//
4
5/*
6 Portions from http://www.adp-gmbh.ch/cpp/common/base64.html
7 Copyright notice:
8
9 base64.cpp and base64.h
10
11 Copyright (C) 2004-2008 René Nyffenegger
12
13 This source code is provided 'as-is', without any express or implied
14 warranty. In no event will the author be held liable for any damages
15 arising from the use of this software.
16
17 Permission is granted to anyone to use this software for any purpose,
18 including commercial applications, and to alter it and redistribute it
19 freely, subject to the following restrictions:
20
21 1. The origin of this source code must not be misrepresented; you must not
22 claim that you wrote the original source code. If you use this source code
23 in a product, an acknowledgment in the product documentation would be
24 appreciated but is not required.
25
26 2. Altered source versions must be plainly marked as such, and must not be
27 misrepresented as being the original source code.
28
29 3. This notice may not be removed or altered from any source distribution.
30
31 René Nyffenegger rene.nyffenegger@adp-gmbh.ch
32
33*/
34
35#pragma once
36
37#include <cstddef>
38#include <cstdint>
39#include <string>
40#include <string_view>
41
42namespace xrpl {
43
44namespace base64 {
45
52constexpr std::size_t
54{
55 return 4 * ((nBytes + 2) / 3);
56}
57
65constexpr std::size_t
66decodedSize(std::size_t const numChars)
67{
68 return ((numChars / 4) * 3) + 2;
69}
70
71} // namespace base64
72
74base64Encode(std::uint8_t const* data, std::size_t len);
75
76inline std::string
78{
79 return base64Encode(reinterpret_cast<std::uint8_t const*>(s.data()), s.size());
80}
81
84
85} // namespace xrpl
T data(T... args)
constexpr std::size_t encodedSize(std::size_t const nBytes)
Returns the maximum number of characters needed to base64-encode nBytes bytes.
Definition base64.h:53
constexpr std::size_t decodedSize(std::size_t const numChars)
Returns the maximum number of bytes a base64 string of numChars characters decodes to.
Definition base64.h:66
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::string base64Decode(std::string_view data)
std::string base64Encode(std::uint8_t const *data, std::size_t len)
T size(T... args)