SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
String.cpp
Go to the documentation of this file.
1
#include <
sourcepp/crypto/String.h
>
2
3
#include <iomanip>
4
#include <sstream>
5
6
#include <cryptopp/hex.h>
7
8
using namespace
sourcepp
;
9
10
std::vector<std::byte>
crypto::decodeHexString
(std::string_view hex) {
11
std::string hexBin;
12
CryptoPP::StringSource hexSource{hex.data(),
true
,
new
CryptoPP::HexDecoder{
new
CryptoPP::StringSink{hexBin}}};
13
14
std::vector<std::byte> out;
15
for
(
char
c : hexBin) {
16
out.push_back(
static_cast<
std::byte
>
(c));
17
}
18
return
out;
19
}
20
21
std::string
crypto::encodeHexString
(std::span<const std::byte> hex) {
22
std::ostringstream oss;
23
oss << std::hex << std::setfill(
'0'
);
24
for
(
auto
byte
: hex) {
25
oss << std::setw(2) << static_cast<int>(std::to_integer<unsigned char>(
byte
));
26
}
27
return
oss.str();
28
}
String.h
sourcepp::crypto::encodeHexString
std::string encodeHexString(std::span< const std::byte > hex)
Definition
String.cpp:21
sourcepp::crypto::decodeHexString
std::vector< std::byte > decodeHexString(std::string_view hex)
Definition
String.cpp:10
sourcepp
Definition
LZMA.h:11
src
sourcepp
crypto
String.cpp
Generated on
for SourcePP by
1.14.0