summaryrefslogtreecommitdiff
path: root/modules/crypto/tests/argon2i.cpp
blob: 9f8efc5f30da4dbec24be7e9759083bc532a4d8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <forstio/test/suite.hpp>
#include <forstio/codec/data.hpp>
#include <forstio/codec/base64.hpp>

#include "../c++/hash.hpp"

#include <iostream>
namespace {
namespace sch {
using namespace saw::schema;
}
SAW_TEST("Codec Base64 Encode String"){
	using namespace saw;

	data<sch::String> inp_data{"Hello, World!"};
	data<sch::String> salt{"salty678"};

	hash<crypto::Argon2i> hasher;

	auto eov = hasher.apply(inp_data, salt);
	SAW_EXPECT(eov.is_value(), (std::string{"Hashing failed. "} + std::string{eov.get_error().get_message()}) );
	auto& val = eov.get_value();
	
	data<sch::String, encode::Base64> base64_str;
	codec<sch::String, encode::Base64> base64_codec;
	auto eob64 = base64_codec.encode(val, base64_str);
	SAW_EXPECT(eob64.is_value(), "Couldn't encode data");
	
	data<sch::String, encode::Base64> check_against{"J082QuWpLuV3UnaVScg4NbUYLfb5VNKp4HAiPOevEbB+EZsxUbwSOoYUNUsXgEcvF2/lbysX0NBGDN5gcc1/TF0YIUi0xGAcNeK6DP5bZckqMrN7WRlCxugmSQLQ18SzDmIKdwxSo2vWO0ivV2m7ZGOxCdrfxZ26ivRUkeazOFA="};
	SAW_EXPECT(base64_str == check_against, "Base64 not expected value");

}
}