Refactored tests, fixed AES test
This commit is contained in:
parent
39b47c36f0
commit
dda63f4fc8
3 changed files with 65 additions and 38 deletions
|
|
@ -338,7 +338,7 @@ target_link_libraries( task_cancel_test fc )
|
|||
add_executable( bloom_test tests/bloom_test.cpp )
|
||||
target_link_libraries( bloom_test fc )
|
||||
|
||||
add_executable( real128_test tests/real128_test.cpp )
|
||||
add_executable( real128_test tests/all_tests.cpp tests/real128_test.cpp )
|
||||
target_link_libraries( real128_test fc )
|
||||
|
||||
|
||||
|
|
@ -358,7 +358,7 @@ target_link_libraries( ecc_test fc )
|
|||
#add_executable( test_rate_limiting tests/rate_limiting.cpp )
|
||||
#target_link_libraries( test_rate_limiting fc )
|
||||
|
||||
add_executable( all_tests tests/all_tests.cpp tests/compress.cpp )
|
||||
add_executable( all_tests tests/all_tests.cpp tests/compress.cpp tests/real128_test.cpp )
|
||||
target_link_libraries( all_tests fc )
|
||||
|
||||
if(WIN32)
|
||||
|
|
|
|||
|
|
@ -1,46 +1,70 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <fc/crypto/aes.hpp>
|
||||
#include <fc/crypto/city.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
|
||||
#include <fc/variant.hpp>
|
||||
int main( int argc, char** )
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(fc_crypto)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(aes_test)
|
||||
{
|
||||
std::string line;
|
||||
std::getline( std::cin, line );
|
||||
auto key = fc::sha512::hash( "hello", 5 );
|
||||
while( std::cin && line != "q" )
|
||||
{
|
||||
try {
|
||||
std::vector<char> data( line.c_str(),line.c_str()+line.size()+1 );
|
||||
std::vector<char> crypt = fc::aes_encrypt( key, data );
|
||||
std::vector<char> dcrypt = fc::aes_decrypt( key, crypt );
|
||||
std::ifstream testfile;
|
||||
testfile.open("README.md");
|
||||
|
||||
std::cout<<"line.size: '"<<line.size()<<"'\n";
|
||||
std::cout<<"data.size: '"<<data.size()<<"'\n";
|
||||
std::cout<<"crypt.size: '"<<crypt.size()<<"'\n";
|
||||
std::cout<<"dcrypt.size: '"<<dcrypt.size()<<"'\n";
|
||||
std::cout<<"line: '"<<line<<"'\n";
|
||||
std::cout<<"dcrypt: '"<<dcrypt.data()<<"'\n";
|
||||
std::cout<<"dcrypt: "<<fc::variant(dcrypt).as_string()<<"\n";
|
||||
std::cout<<"crypt: "<<fc::variant(crypt).as_string()<<"\n";
|
||||
memset( crypt.data(), 0, crypt.size() );
|
||||
|
||||
fc::aes_encoder enc;
|
||||
enc.init( fc::sha256::hash((char*)&key,sizeof(key) ), fc::city_hash_crc_128( (char*)&key, sizeof(key) ) );
|
||||
auto len = enc.encode( dcrypt.data(), dcrypt.size(), crypt.data() );
|
||||
// enc.final_encode( crypt.data() + len );
|
||||
std::cout<<"crypt: "<<fc::variant(crypt).as_string()<<"\n";
|
||||
|
||||
|
||||
fc::aes_decoder dec;
|
||||
dec.init( fc::sha256::hash((char*)&key,sizeof(key) ), fc::city_hash_crc_128( (char*)&key, sizeof(key) ) );
|
||||
}
|
||||
catch ( fc::exception& e )
|
||||
auto key = fc::sha512::hash( "hello", 5 );
|
||||
std::stringstream buffer;
|
||||
std::string line;
|
||||
std::getline( testfile, line );
|
||||
while( testfile.good() )
|
||||
{
|
||||
std::cout<<e.to_detail_string()<<"\n";
|
||||
// std::cout << line << "\n";
|
||||
buffer << line << "\n";
|
||||
try {
|
||||
std::vector<char> data( line.c_str(),line.c_str()+line.size()+1 );
|
||||
std::vector<char> crypt = fc::aes_encrypt( key, data );
|
||||
std::vector<char> dcrypt = fc::aes_decrypt( key, crypt );
|
||||
BOOST_CHECK( data == dcrypt );
|
||||
|
||||
// memset( crypt.data(), 0, crypt.size() );
|
||||
// fc::aes_encoder enc;
|
||||
// enc.init( fc::sha256::hash((char*)&key,sizeof(key) ), fc::city_hash_crc_128( (char*)&key, sizeof(key) ) );
|
||||
// auto len = enc.encode( dcrypt.data(), dcrypt.size(), crypt.data() );
|
||||
// BOOST_CHECK_EQUAL( dcrypt.size(), len );
|
||||
//
|
||||
// fc::aes_decoder dec;
|
||||
// dec.init( fc::sha256::hash((char*)&key,sizeof(key) ), fc::city_hash_crc_128( (char*)&key, sizeof(key) ) );
|
||||
// len = dec.decode( crypt.data(), len, dcrypt.data() );
|
||||
// BOOST_CHECK_EQUAL( dcrypt.size(), len );
|
||||
// BOOST_CHECK( !memcmp( dcrypt.data(), data.data(), len) );
|
||||
}
|
||||
catch ( fc::exception& e )
|
||||
{
|
||||
std::cout<<e.to_detail_string()<<"\n";
|
||||
}
|
||||
std::getline( testfile, line );
|
||||
}
|
||||
std::getline( std::cin, line );
|
||||
}
|
||||
return 0;
|
||||
|
||||
line = buffer.str();
|
||||
std::vector<char> data( line.c_str(),line.c_str()+line.size()+1 );
|
||||
std::vector<char> crypt = fc::aes_encrypt( key, data );
|
||||
std::vector<char> dcrypt = fc::aes_decrypt( key, crypt );
|
||||
BOOST_CHECK( data == dcrypt );
|
||||
|
||||
// memset( crypt.data(), 0, crypt.size() );
|
||||
// fc::aes_encoder enc;
|
||||
// enc.init( fc::sha256::hash((char*)&key,sizeof(key) ), fc::city_hash_crc_128( (char*)&key, sizeof(key) ) );
|
||||
// auto len = enc.encode( dcrypt.data(), dcrypt.size(), crypt.data() );
|
||||
// BOOST_CHECK_EQUAL( dcrypt.size(), len );
|
||||
//
|
||||
// fc::aes_decoder dec;
|
||||
// dec.init( fc::sha256::hash((char*)&key,sizeof(key) ), fc::city_hash_crc_128( (char*)&key, sizeof(key) ) );
|
||||
// len = dec.decode( crypt.data(), len, dcrypt.data() );
|
||||
// BOOST_CHECK_EQUAL( dcrypt.size(), len );
|
||||
// BOOST_CHECK( !memcmp( dcrypt.data(), data.data(), len) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
#include <fc/real128.hpp>
|
||||
#define BOOST_TEST_MODULE Real128Test
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(fc)
|
||||
|
||||
using fc::real128;
|
||||
using std::string;
|
||||
|
||||
|
|
@ -50,3 +51,5 @@ BOOST_AUTO_TEST_CASE(real128_test)
|
|||
wdump((real128("12345.6789")) );
|
||||
wdump( (ten/3*3) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
|
|||
Loading…
Reference in a new issue