From a67fdaa1ef1e3a5eea88d19e327c05330998e8aa Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 31 Oct 2006 05:41:13 +0000 Subject: Added an sha1 class... --- src/tests/sha1.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/tests/sha1.cpp (limited to 'src/tests/sha1.cpp') diff --git a/src/tests/sha1.cpp b/src/tests/sha1.cpp new file mode 100644 index 0000000..51c5104 --- /dev/null +++ b/src/tests/sha1.cpp @@ -0,0 +1,44 @@ +#include "sha1.h" +#include "file.h" + +#define BS 1024 + +int main( int argc, char *argv[] ) +{ + argc--; argv++; + + if( argc == 0 ) + { + printf("Provide a filename.\n"); + return 0; + } + + char buf[BS]; + + Sha1 s; + File fin( *argv, "rb" ); + for(;;) + { + int nRead = fin.read( buf, BS ); + if( nRead == 0 ) + break; + + s.update( buf, nRead ); + if( nRead < BS ) + break; + } + + unsigned char *dig = s.getDigest(); + + char val[]={"0123456789ABCDEF"}; + + for( int j = 0; j < 20; j++ ) + { + putchar( val[dig[j]>>4] ); + putchar( val[dig[j]&0x0F] ); + } + putchar('\n'); + + delete[] dig; +} + -- cgit v1.2.3