summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/codec/tests/base64.cpp6
-rw-r--r--modules/crypto/.nix/derivation.nix3
-rw-r--r--modules/crypto/SConstruct6
-rw-r--r--modules/crypto/c++/hash.hpp6
-rw-r--r--modules/crypto/tests/argon2i.cpp33
5 files changed, 46 insertions, 8 deletions
diff --git a/modules/codec/tests/base64.cpp b/modules/codec/tests/base64.cpp
index 7fb986b..b52a6bf 100644
--- a/modules/codec/tests/base64.cpp
+++ b/modules/codec/tests/base64.cpp
@@ -2,12 +2,11 @@
#include "../c++/data.hpp"
#include "../c++/base64.hpp"
-#include <iostream>
namespace {
namespace sch {
using namespace saw::schema;
}
-SAW_TEST("Codec Base64 Encode String"){
+SAW_TEST("Argon2i Hash String"){
using namespace saw;
data<sch::String> inp_data{"Hello, World!"};
@@ -19,6 +18,7 @@ SAW_TEST("Codec Base64 Encode String"){
auto eov = base64_codec.encode(inp_data, base64_str);
SAW_EXPECT(eov.is_value(), "Couldn't encode data");
- SAW_EXPECT((base64_str == data<sch::String, encode::Base64>{"SGVsbG8sIFdvcmxkIQ=="}), "Base64 not expected value");
+ data<sch::String, encode::Base64> check_against{"SGVsbG8sIFdvcmxkIQ=="};
+ SAW_EXPECT(base64_str == check_against, "Base64 not expected value");
}
}
diff --git a/modules/crypto/.nix/derivation.nix b/modules/crypto/.nix/derivation.nix
index d470509..827eac0 100644
--- a/modules/crypto/.nix/derivation.nix
+++ b/modules/crypto/.nix/derivation.nix
@@ -22,7 +22,8 @@ in stdenv.mkDerivation {
];
buildInputs = [
- forstio.core
+ forstio.core
+ forstio.codec
libargon2
];
diff --git a/modules/crypto/SConstruct b/modules/crypto/SConstruct
index f71db5a..a2b6f96 100644
--- a/modules/crypto/SConstruct
+++ b/modules/crypto/SConstruct
@@ -46,7 +46,11 @@ env_vars.Add('prefix',
env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
CPPDEFINES=['SAW_UNIX'],
CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'],
- LIBS=['forstio-core'])
+ LIBS=[
+ 'forstio-core'
+ ,'argon2'
+ ]
+)
env.__class__.add_source_files = add_kel_source_files
env.Tool('compilation_db');
env.cdb = env.CompilationDatabase('compile_commands.json');
diff --git a/modules/crypto/c++/hash.hpp b/modules/crypto/c++/hash.hpp
index 5898adc..8e8ca86 100644
--- a/modules/crypto/c++/hash.hpp
+++ b/modules/crypto/c++/hash.hpp
@@ -20,7 +20,7 @@ public:
uint32_t t_cost = 2;
uint32_t m_cost = 1<<16;
uint32_t parallel = 1;
- char* salt_c_ptr = nullptr;
+ const char* salt_c_ptr = nullptr;
if(salt.size() > 0){
salt_c_ptr = &salt.at(0);
}
@@ -30,8 +30,8 @@ public:
}catch(const std::exception&){
return make_error<err::out_of_memory>("Couldn't allocate hash string");
}
- int rv = argon2i_hash_raw(t_cost, m_cost, parallel, &input.at(0), input.size(), &salt.at(0), salt.size(), &hash.at(0), hash.size());
- if(rc != ARGON2_OK){
+ int rv = argon2i_hash_raw(t_cost, m_cost, parallel, &input.at(0), input.size(), salt_c_ptr, salt.size(), &hash.at(0), hash.size());
+ if(rv != ARGON2_OK){
return make_error<err::invalid_state>("Failed to hash");
}
diff --git a/modules/crypto/tests/argon2i.cpp b/modules/crypto/tests/argon2i.cpp
new file mode 100644
index 0000000..9f8efc5
--- /dev/null
+++ b/modules/crypto/tests/argon2i.cpp
@@ -0,0 +1,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");
+
+}
+}