4
* 2004-May-20 Jason Rohrer
11
#include "minorGems/formats/encodingUtils.h"
19
* Prints usage message and exits.
21
* @param inAppName the name of the app.
23
void usage( char *inAppName );
27
int main( int inNumArgs, char **inArgs ) {
30
if( inNumArgs != 2 ) {
35
FILE *file = fopen( inArgs[1], "rb" );
38
printf( "Failed to open file %s for reading\n\n", inArgs[1] );
46
SHA1_Init( &shaContext );
49
int bufferSize = 5000;
50
unsigned char *buffer = new unsigned char[ bufferSize ];
52
int numRead = bufferSize;
56
// read bytes from file until we run out
57
while( numRead == bufferSize && !error ) {
59
numRead = fread( buffer, 1, bufferSize, file );
62
SHA1_Update( &shaContext, buffer, numRead );
74
printf( "Error reading from file %s\n", inArgs[1] );
77
unsigned char *rawDigest = new unsigned char[ SHA1_DIGEST_LENGTH ];
79
SHA1_Final( rawDigest, &shaContext );
81
// else hash is correct
82
char *digestHexString = hexEncode( rawDigest, SHA1_DIGEST_LENGTH );
84
printf( "%s %s\n", digestHexString, inArgs[1] );
87
delete [] digestHexString;
95
void usage( char *inAppName ) {
97
printf( "Usage:\n\n" );
98
printf( "\t%s file_to_sum\n", inAppName );
100
printf( "example:\n" );
102
printf( "\t%s test.txt\n", inAppName );