Ring Daemon
16.0.0
Loading...
Searching...
No Matches
base64.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16
*/
17
18
#include "
base64.h
"
19
#include "
connectivity/sip_utils.h
"
20
21
#include <pjlib.h>
22
#include <pjlib-util/base64.h>
23
24
namespace
jami
{
25
namespace
base64 {
26
27
std::string
28
encode
(std::string_view
dat
)
29
{
30
if
(
dat
.empty() ||
dat
.size() >
INT_MAX
)
31
return
{};
32
33
int
input_length
= (
int
)
dat
.size();
34
int
output_length
=
PJ_BASE256_TO_BASE64_LEN
(
input_length
);
35
std::string
out
;
36
out
.resize(
output_length
);
37
38
if
(
pj_base64_encode
((
const
uint8_t
*)
dat
.data(),
input_length
, &(*
out
.begin()), &
output_length
) !=
PJ_SUCCESS
) {
39
throw
base64_exception
();
40
}
41
42
out
.resize(
output_length
);
43
return
out
;
44
}
45
46
std::vector<uint8_t>
47
decode
(std::string_view
str
)
48
{
49
if
(
str
.empty())
50
return
{};
51
52
int
output_length
=
PJ_BASE64_TO_BASE256_LEN
(
str
.length());
53
auto
input =
sip_utils::CONST_PJ_STR
(
str
);
54
55
std::vector<uint8_t>
out
;
56
out
.resize(
output_length
);
57
58
if
(
pj_base64_decode
(&input, &(*
out
.begin()), &
output_length
) !=
PJ_SUCCESS
) {
59
throw
base64_exception
();
60
}
61
62
out
.resize(
output_length
);
63
return
out
;
64
}
65
66
}
// namespace base64
67
}
// namespace jami
base64.h
jami::base64::base64_exception
Definition
base64.h:30
jami::base64::decode
std::vector< uint8_t > decode(std::string_view str)
Definition
base64.cpp:47
jami::base64::encode
std::string encode(std::string_view dat)
Definition
base64.cpp:28
jami::sip_utils::CONST_PJ_STR
constexpr const pj_str_t CONST_PJ_STR(T(&a)[N]) noexcept
Definition
sip_utils.h:89
jami
Definition
account.cpp:61
jami::emitSignal
void emitSignal(Args... args)
Definition
ring_signal.h:64
sip_utils.h
src
base64.cpp
Generated on Thu Jun 19 2025 15:50:36 for Ring Daemon by
1.9.8