24#include <catch2/catch.hpp>
34 bool isInputDataInitialized =
false;
35 vector<string> inputData;
43 std::string genRandomUnicode(
size_t len,
unsigned int rseed) {
44 const char cl[][50] = {
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
45 "s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
" ",
"\t",
"<",
">",
"\"",
"=",
"ä",
"ö",
"ü",
47 "é",
"ó",
"ú",
"𝔸",
"@",
"#",
"$",
"€",
"?",
"!",
"/",
"\\",
"-",
"~"};
49 default_random_engine dre(rseed);
50 uniform_int_distribution<size_t> distribution(0, 49);
51 for (
size_t i = len; i > 0; --i) {
52 ret << cl[distribution(dre)];
57 void initializeInputDataIfNotYetDone() {
58 if (isInputDataInitialized) {
61 for (
unsigned int rseed = 0; rseed < 10; ++rseed) {
62 inputData.push_back(genRandomUnicode(100, rseed));
64 isInputDataInitialized =
true;
68TEST_CASE(
"nawa::encoding functions",
"[unit][encoding]") {
69 SECTION(
"punycode encoding") {
70 string punycodeEncoded =
"xn--bcher-kuflich-erwrben-c2b9jut.xy";
71 string punycodeDecoded =
"bücher-käuflich-erwérben.xy";
72 string asciiDomain =
"example.com";
78 initializeInputDataIfNotYetDone();
79 string decoded = GENERATE(from_range(inputData));
81 SECTION(
"HTML encoding") {
82 string htmlDecoded = R
"(<input type="text" value="tä𝔸𝔸𝔸st">)";
84 string htmlEncoded2 = R
"(<input type="text" value="tä𝔸𝔸𝔸st">)";
85 CHECK(htmlEncoded.length() > htmlDecoded.length());
94 SECTION(
"URL encoding") {
95 string urlDecoded =
"bla bla bla!??xyzäßédsfsdf ";
102 SECTION(
"Base64 encoding") {
108 SECTION(
"quoted-printable encoding") {
123 initializeInputDataIfNotYetDone();
124 string decoded = GENERATE(from_range(inputData));
126 SECTION(
"bcrypt password hashing") {
131 SECTION(
"argon2 password hashing") {
134 hashing::Argon2HashingEngine::Algorithm::ARGON2ID, 2, 1 << 16,
138 hashing::Argon2HashingEngine::Algorithm::ARGON2I));
141 hashing::Argon2HashingEngine::Algorithm::ARGON2D));
A bunch of useful cryptographic functions (esp. hashing), acting as a wrapper to C crypto libraries.
Namespace containing functions for text encoding and decoding.
TEST_CASE("nawa::encoding functions", "[unit][encoding]")
bool passwordVerify(std::string const &password, std::string const &hash, hashing::HashTypeTable const &hashTypeTable=hashing::DefaultHashTypeTable())
std::string passwordHash(std::string const &password, hashing::HashingEngine const &hashingEngine=hashing::BcryptHashingEngine())
std::string base64Decode(std::string const &input)
std::string quotedPrintableDecode(std::string input, bool qEncoding=false)
std::string base64Encode(std::string const &input, size_t breakAfter=0, std::string const &breakSequence="")
std::string quotedPrintableEncode(std::string const &input, std::string const &lineEnding="\r\n", bool replaceCrlf=false, bool qEncoding=false)
std::string punycodeEncode(std::string const &input)
std::string punycodeDecode(std::string const &input)
std::string urlEncode(std::string const &input)
bool isBase64(std::string const &input, bool allowWhitespaces=true)
std::string urlDecode(std::string input)
std::string htmlEncode(std::string input, bool encodeAll=false)
std::string htmlDecode(std::string input)