27 #include <boost/filesystem/operations.hpp> 40 const char*
hashEmpty_ =
"da39a3ee5e6b4b0d3255bfef95601890afd80709";
42 const char*
textBrown_ =
"The quick brown fox jumps over the lazy dog";
43 const char*
hashBrown_ =
"2fd4e1c67a2d28fced849ee1bb76e7391b93eb12";
46 const char*
hashabc_ =
"a9993e364706816aba3e25717850c26c9cd0d89d";
48 const char*
textabc2_ =
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
49 const char*
hashabc2_ =
"84983e441c3bd26ebaae4aa1f95129e5e54670f1";
51 const char*
hashMillion_ =
"34aa973cd4c4daa4f61eeb2bdbad27316534016f";
58 string temp = sha1.
hash();
59 if (
os_) *
os_ <<
"hash empty: " << temp << endl;
66 if (
os_) *
os_ <<
"hash brown: " << temp << endl;
75 if (
os_) *
os_ <<
"hash stream: " << hash << endl;
76 unit_assert(hash ==
"2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
82 const char* filename =
"sha1test.test.txt";
83 ofstream os(filename);
89 if (
os_) *
os_ <<
"hash file: " << hash << endl;
90 unit_assert(hash ==
"2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
94 ifstream filestream(filename, ios::binary);
96 if (
os_) *
os_ <<
"hash stream: " << hash << endl;
97 unit_assert(hash ==
"2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
100 boost::filesystem::remove(filename);
110 if (
os_) *
os_ <<
"hash abc: " << temp << endl;
114 if (
os_) *
os_ <<
"hash abc2: " << temp << endl;
124 for (
int i=0; i<100000; i++)
128 string temp = sha1.
hash();
129 if (
os_) *
os_ <<
"hash million: " << temp << endl;
140 if (
os_) *
os_ <<
"projected: " << projected << endl;
146 string final = sha1.
hash();
152 int main(
int argc,
char* argv[])
158 if (argc>1 && !strcmp(argv[1],
"-v"))
161 if (
os_) *
os_ <<
"sha1test\n";
void close()
finish the hash
static std::string hashFile(const std::string &filename)
static function to calculate hash of a file
char verify_int_is_32_bits[(sizeof(int)==4) *2-1]
std::string hashProjected() const
returns projected final hash value as if close() were called first; hash remains open and update() ma...
std::string hash() const
returns the current hash value note: close() must be called first to retrieve final hash value ...
void update(const unsigned char *buffer, size_t bufferSize)
update hash with buffer of bytes
const char * hashMillion_
#define TEST_PROLOG(argc, argv)
int main(int argc, char *argv[])