X-Git-Url: https://jxself.org/git/?p=skeinsum.git;a=blobdiff_plain;f=skein_cli.c;h=39fb01ac3087204a0fd4d005c2c9d3e5008aeb98;hp=e95f4b60844f9e90db443def874a87c9e453d678;hb=28de312cd6c2d32822e2b2ce793abbdf2ae640dc;hpb=a20d5ede618124ecba406fcca37cf92dbc202997 diff --git a/skein_cli.c b/skein_cli.c index e95f4b6..39fb01a 100644 --- a/skein_cli.c +++ b/skein_cli.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 2015 Jason Self +/* Copyright (C) 2014 2015 2019 Jason Self This file is part of skeinsum. @@ -166,7 +166,7 @@ int HashFile(const char file_name[], char MsgDigest[], char mode) } unsigned char output[hashbitlen/4]; - Hash(hashbitlen, (unsigned char*) readbuf, total_readed, output); + Hash(hashbitlen, (unsigned char*) readbuf, total_readed * 8, output); free(readbuf); @@ -366,9 +366,18 @@ int VerifyHashesFromFile(FILE *fp, int status, int warn, int quiet) return (NotProper || NoMatch) ? -1 : 1; } +void PrintStringHash(const char *s) +{ + unsigned char output[hashbitlen/4]; + char digest[hashbitlen/4 + 1]; + Hash(hashbitlen, s, strlen(s) * 8, output); + hash2hexstr(output, digest); + printf("%s -%s\n", digest, s); +} + void print_version(void) { - printf("skein%dsum 1.0\n", hashbitlen); + printf("skein%dsum %s\n", hashbitlen, VERSION); printf("License GPLv3+: GNU GPL version 3 or later\n"); printf("\n"); printf("This is free software: you are free to change and redistribute it.\n"); @@ -432,6 +441,27 @@ int is_goodfile(const char filename[]) return 1; /* try it as good */ } +int warn_check_opts(int quiet, int warn, int status) +{ + int n = 0; + if(quiet == 1) + n = WARN("the --quiet option is meaningful only when verifying checksums\n"); + if(status ==1) + n = WARN("the --status option is meaningful only when verifying checksums\n"); + if(warn == 1) + n = WARN("the --warn option is meaningful only when verifying checksums\n"); + return n; +} + +int warn_gen_opts(int tag, int binary) +{ + int n = 0; + if (tag == 1) + n = WARN("the --tag option is meaningful only when calculating file checksums\n"); + if (binary >= 0) + n = WARN("the --text and --binary options are meaningful only when calculating file checksums\n"); + return n; +} int main(int argc, char** argv) { @@ -476,33 +506,23 @@ int main(int argc, char** argv) if (hashString > 0) { + if (warn_check_opts(quiet, warn, status) + warn_gen_opts(tag, binary)) + TRYHELP_GOODBYE(); + int n = first_file; if (n >= argc) { WARN("command line should contain strings for hashing\n"); TRYHELP_GOODBYE(); } - for( ; n < argc; n++) { - unsigned char output[hashbitlen/4]; - char digest[hashbitlen/4 + 1]; - Hash(hashbitlen, argv[n], strlen(argv[n]), output); - hash2hexstr(output, digest); - printf("%s -%s\n", digest, argv[n]); - } + while (n < argc) + PrintStringHash(argv[n++]); return 0; } if (check < 0) /* READ FILES, GENERATE CHECKSUMS AND PRINT TO STDOUT.. */ { - if (quiet == 1 || warn == 1 || status == 1) - { - if(quiet == 1) - WARN("the --quiet option is meaningful only when verifying checksums\n"); - if(status ==1) - WARN("the --status option is meaningful only when verifying checksums\n"); - if(warn == 1) - WARN("the --warn option is meaningful only when verifying checksums\n"); + if (warn_check_opts(quiet, warn, status)) TRYHELP_GOODBYE(); - } char mode = binary > 0 ? 'b' : 't'; @@ -533,14 +553,8 @@ int main(int argc, char** argv) if (check == 1) /* READ LISTFILES, GENERATE HASHES, COMPARE WITH STORED, PRINT RESULT */ { - if (tag == 1 || binary >= 0) - { - if (tag == 1) - WARN("the --tag option is meaningless when verifying checksums\n"); - if (binary >= 0) - WARN("the --text and --binary options are meaningless when verifying checksums\n"); + if (warn_gen_opts(tag, binary)) TRYHELP_GOODBYE(); - } int file_index; for (file_index = first_file; file_index < argc; file_index++)