File: test-crypto.cc

package info (click to toggle)
weakforced 3.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,040 kB
  • sloc: cpp: 20,397; python: 2,002; sh: 700; makefile: 432
file content (25 lines) | stat: -rw-r--r-- 645 bytes parent folder | download
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
#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();