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.
2
3#include <iomanip>
4#include <sstream>
5
6#include <cryptopp/hex.h>
7
8using namespace sourcepp;
9
10std::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
21std::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}
std::string encodeHexString(std::span< const std::byte > hex)
Definition: String.cpp:21
std::vector< std::byte > decodeHexString(std::string_view hex)
Definition: String.cpp:10
Definition: LZMA.h:11