From: Jason Self Date: Mon, 14 Sep 2015 02:55:59 +0000 (-0700) Subject: Merge matching code to new HashStdin routine. X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=e51312b923ee11adcc9b9f7c63385e7660de136f;p=skeinsum.git Merge matching code to new HashStdin routine. --- diff --git a/skein_cli.c b/skein_cli.c index bbe820c..011f98f 100644 --- a/skein_cli.c +++ b/skein_cli.c @@ -183,12 +183,26 @@ int HashBinaryMode(char file_name[], char MsgDigest[]) return HashWithMode(file_name, MsgDigest, 'b'); } -int HashStringMode(char Msg[],char MsgDigest[]) +void HashStringMode(char Msg[],char MsgDigest[]) { unsigned char output[hashbitlen/4]; Hash(hashbitlen,(unsigned char*) Msg,sizeof(Msg),output); printHexMsg(output,hashbitlen/4,MsgDigest); - return 1; +} + +void HashStdin(char MsgDigest[], int tag) +{ + char stri[100]; + char longstring[1000]; + longstring[0] = 0; + while(fgets(stri,100,stdin)) + strcat(longstring, stri); + HashStringMode(longstring, MsgDigest); + if (tag) { + printf("skein%d_v%s (-) = %s\n", hashbitlen, skeinVersion, MsgDigest); + } else { + printf("%s *-\n", MsgDigest); + } } int isProper(char MsgDigest[]) @@ -440,23 +454,8 @@ int main(int argc, char** argv) } } else if(errorFound != 1) - { // read stdin for strings - char stri[100]; - char longstring[1000]; - longstring[0] = 0; - while((fgets(stri,100,stdin))!=NULL) - { - strcat(longstring,stri); - } - HashStringMode(longstring,MsgDigest); - if(tag == 1) - { - printf("skein%d_v%s (-) = %s\n",hashbitlen,skeinVersion,MsgDigest); - } - else - { - printf("%s *-\n",MsgDigest); - } + { + HashStdin(MsgDigest, tag); } } @@ -489,23 +488,8 @@ int main(int argc, char** argv) } } else if(errorFound != 1) - { // read stdin for strings - char stri[100]; - char longstring[1000]; - longstring[0] = 0; - while((fgets(stri,100,stdin))!=NULL) - { - strcat(longstring,stri); - } - HashStringMode(longstring,MsgDigest); - if(tag == 1) - { - printf("skein%d_v%s (-) = %s\n",hashbitlen,skeinVersion,MsgDigest); - } - else - { - printf("%s -\n",MsgDigest); - } + { + HashStdin(MsgDigest, tag); } } @@ -546,23 +530,8 @@ int main(int argc, char** argv) } } else if(errorFound != 1) - { // hasing strings read from stdin - char stri[100]; - char longstring[1000]; /* TODO!!! Fix buffer overflow!!! */ - longstring[0] = 0; - while((fgets(stri,100,stdin))!=NULL) - { - strcat(longstring,stri); - } - HashStringMode(longstring,MsgDigest); - if(tag == 1) - { - printf("skein%d_v%s (-) = %s\n",hashbitlen,skeinVersion,MsgDigest); - } - else - { - printf("%s -\n",MsgDigest); - } + { + HashStdin(MsgDigest, tag); } } else if(check == 1) @@ -726,18 +695,8 @@ int main(int argc, char** argv) } } - if ((errorFound != 1) && (argc == 1 || (hashString == 1 && number_files == 0))) - { - char stri[100]; - char longstring[1000]; - longstring[0] = 0; - while((fgets(stri,100,stdin))!=NULL) - { - strcat(longstring,stri); - } - HashStringMode(longstring,MsgDigest); - printf("%s -\n",MsgDigest); - } + if (!errorFound && (argc == 1 || (hashString == 1 && !number_files))) + HashStdin(MsgDigest, 0); return 1; }