xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
basics
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
42
namespace
xrpl
{
43
44
namespace
base64
{
45
52
constexpr
std::size_t
53
encodedSize
(
std::size_t
const
nBytes)
54
{
55
return
4 * ((nBytes + 2) / 3);
56
}
57
65
constexpr
std::size_t
66
decodedSize
(
std::size_t
const
numChars)
67
{
68
return
((numChars / 4) * 3) + 2;
69
}
70
71
}
// namespace base64
72
73
std::string
74
base64Encode
(
std::uint8_t
const
* data,
std::size_t
len);
75
76
inline
std::string
77
base64Encode
(
std::string_view
s)
78
{
79
return
base64Encode
(
reinterpret_cast<
std::uint8_t
const*
>
(s.
data
()), s.
size
());
80
}
81
82
std::string
83
base64Decode
(
std::string_view
data);
84
85
}
// namespace xrpl
std::string
std::string_view
cstddef
cstdint
std::string_view::data
T data(T... args)
std::uint8_t
xrpl::base64
Definition
base64.h:44
xrpl::base64::encodedSize
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
xrpl::base64::decodedSize
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
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::base64Decode
std::string base64Decode(std::string_view data)
Definition
libxrpl/basics/base64.cpp:199
xrpl::base64Encode
std::string base64Encode(std::uint8_t const *data, std::size_t len)
Definition
libxrpl/basics/base64.cpp:190
std::string_view::size
T size(T... args)
std::size_t
string
string_view
Generated by
1.17.0