Skip to content

Commit

Permalink
common: Add test-crypto.cc to git
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcook committed Dec 2, 2024
1 parent f3b5568 commit 6b3213f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions common/test-crypto.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_NO_MAIN
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <boost/test/unit_test.hpp>
#include "sodcrypto.hh"

BOOST_AUTO_TEST_SUITE(test_crypto)

BOOST_AUTO_TEST_CASE(test_symmetric)
{
std::string keyStr = newKeyStr();
SodiumNonce wnonce, rnonce;
wnonce.init();
memcpy((char*)&rnonce, wnonce.value, sizeof(rnonce.value));
std::string ciphertext, plaintext;
std::string msg("Hello");
ciphertext= sodEncryptSym(msg, keyStr, wnonce);
plaintext= sodDecryptSym(ciphertext, keyStr, rnonce);
BOOST_CHECK(plaintext == msg);
}

BOOST_AUTO_TEST_SUITE_END();

0 comments on commit 6b3213f

Please sign in to comment.