Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/BLAKE2/BLAKE2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/b2sum
diff options
context:
space:
mode:
authorArtem Chudinov <arzeth0@gmail.com>2015-10-30 19:42:01 +0300
committerArtem Chudinov <arzeth0@gmail.com>2015-10-30 19:42:01 +0300
commit70acf250b99973c7b44dd476065ea53fd14e874a (patch)
treeed77e83197b275db5b44f3dce32a3d770469c667 /b2sum
parent918e39086b0a686a6a0417fd8e898a830567bc28 (diff)
b2sum: Support a BSD-style checksum and improve the --help message
Diffstat (limited to 'b2sum')
-rw-r--r--b2sum/b2sum.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/b2sum/b2sum.c b/b2sum/b2sum.c
index 9d64900..55c6136 100644
--- a/b2sum/b2sum.c
+++ b/b2sum/b2sum.c
@@ -20,6 +20,7 @@
#include <ctype.h>
#include <unistd.h>
#include <getopt.h>
+#include <stdbool.h>
#include "blake2.h"
@@ -231,9 +232,14 @@ typedef int ( *blake2fn )( FILE *, void * );
static void usage( char **argv, int errcode )
{
FILE *out = errcode ? stderr : stdout;
- fprintf( out, "Usage: %s [-a HASH] [FILE]...\n", argv[0] );
- fprintf( out, "\tHASH in blake2b blake2s blake2bp blake2sp\n" );
- fprintf( out, "\tWith no FILE, or when FILE is -, read standard input.\n" );
+ fprintf( out, "Usage: %s [OPTION]... [FILE]...\n", argv[0] );
+ fprintf( out, "\n" );
+ fprintf( out, "With no FILE, or when FILE is -, read standard input.\n" );
+ fprintf( out, "\n" );
+ fprintf( out, " -a <hash> hash algorithm (blake2b is default): \n"
+ " [blake2b|blake2s|blake2bp|blake2sp]\n" );
+ fprintf( out, " --tag create a BSD-style checksum\n" );
+ fprintf( out, " --help display this help and exit\n" );
exit( errcode );
}
@@ -243,6 +249,7 @@ int main( int argc, char **argv )
blake2fn blake2_stream = blake2b_stream;
size_t outlen = BLAKE2B_OUTBYTES;
unsigned char hash[BLAKE2B_OUTBYTES] = {0};
+ bool bsdstyle = false;
int c;
opterr = 1;
@@ -252,16 +259,13 @@ int main( int argc, char **argv )
int option_index = 0;
static struct option long_options[] = {
{ "help", no_argument, 0, 0 },
+ { "tag", no_argument, 0, 0 },
{ NULL, 0, NULL, 0 }
};
c = getopt_long( argc, argv, "a:", long_options, &option_index );
if( c == -1 ) break;
switch( c )
{
- case 0:
- if( 0 == strcmp( "help", long_options[option_index].name ) )
- usage( argv, 0 );
- break;
case 'a':
if( 0 == strcmp( optarg, "blake2b" ) )
{
@@ -291,6 +295,13 @@ int main( int argc, char **argv )
break;
+ case 0:
+ if( 0 == strcmp( "help", long_options[option_index].name ) )
+ usage( argv, 0 );
+ else if( 0 == strcmp( "tag", long_options[option_index].name ) )
+ bsdstyle = true;
+ break;
+
case '?':
usage( argv, 1 );
break;
@@ -320,10 +331,22 @@ int main( int argc, char **argv )
goto end1;
}
+ if( bsdstyle )
+ {
+ if( blake2_stream == blake2b_stream ) printf( "BLAKE2b" );
+ else if( blake2_stream == blake2bp_stream ) printf( "BLAKE2bp" );
+ else if( blake2_stream == blake2s_stream ) printf( "BLAKE2s" );
+ else if( blake2_stream == blake2sp_stream ) printf( "BLAKE2sp" );
+ printf( " (%s) = ", argv[i] );
+ }
+
for( int j = 0; j < outlen; ++j )
printf( "%02x", hash[j] );
- printf( " %s\n", argv[i] );
+ if( bsdstyle )
+ printf( "\n" );
+ else
+ printf( " %s\n", argv[i] );
end1:
if( f != stdin ) fclose( f );
end0: ;