void test_basic_hashing() { SHA512 hasher; hasher.write("vossibaer"); hasher.close(); assert(hasher.gethash() == reference_hash("vossibaer")); SHA512 tigger; tigger.write("honey"); tigger.close(); assert(tigger.gethash() == reference_hash("honey")); SHA512 leo; leo.write("lifestyle"); leo.close(); const unsigned char should[64] = { 0xc0, 0x25, 0xb1, 0x2c, 0x03, 0xa6, 0xea, 0x2d, 0xe6, 0x76, 0x00, 0xf5, 0x79, 0x25, 0xb0, 0x60, 0xdd, 0x70, 0xa5, 0xbd, 0x02, 0xb1, 0x4f, 0x39, 0x7f, 0x4e, 0x69, 0x95, 0xec, 0xaa, 0xd4, 0x4c, 0xfc, 0x66, 0xaf, 0xc8, 0xea, 0xcd, 0x61, 0x55, 0x1f, 0x00, 0x93, 0x7c, 0x03, 0x31, 0x83, 0xff, 0x30, 0xa8, 0xb3, 0xe5, 0xbd, 0x45, 0xaf, 0x2c, 0x1b, 0x56, 0xbd, 0xf0, 0x44, 0xf1, 0x58, 0x95, }; unsigned char current[64]; leo.gethash(current); for(int i = 0; i < 64; ++i) { assert(should[i] == current[i]); } }
void test_hashing_errors() { bool caught_exception = false; SHA512 test; test << "hello"; string hash; try { hash = test.gethash(); } catch(std::runtime_error e) { caught_exception = true; } assert(caught_exception); test.close(); caught_exception = false; try { test << "more"; } catch(std::runtime_error e) { caught_exception = true; } assert(caught_exception); }