amiga-sha/sha_amiga.c

109 lines
2.9 KiB
C

/*
* Copyright (c) 2015 Carsten Larsen
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define ARGSFORMAT "S1=SHA1/S,S2=SHA256/S,S3=SHA384/S,S5=SHA512/K,FILES/M,H=HELP/K"
#include "platform.h"
const char *vers = VERSION_STRING_AMIGA;
struct shaargs {
long sha1;
long sha256;
long sha384;
long sha512;
char **files;
long help;
};
int main(int argc, char **argv)
{
int i;
FILE *f;
int opt = 0;
int which = 0;
int failure = 0;
struct shaargs args = {
FALSE, FALSE, FALSE, FALSE, NULL, FALSE
};
atexit(clean_exit);
alloc_buffer();
rdargs = ReadArgs(ARGS_FORMAT, (APTR)&args, NULL);
if (!rdargs)
{
args_error(argv[0]);
exit(5);
}
if (args.sha1) {
which = 1;
opt++;
}
if (args.sha256) {
which = 2;
opt++;
}
if (args.sha384) {
which = 3;
opt++;
}
if (args.sha512) {
which = 4;
opt++;
}
if (args.help || opt != 1) {
fprintf (stderr,
"Options:\n"
"S1\tUse SHA-1\n"
"S2\tUse SHA-256\n"
"S3\tUse SHA-384\n"
"S5\tUse SHA-512\n"
"H\tDisplay this summary\n\n"
"Only one of S1, S2, S3, S5 may be specified\n");
exit(1);
}
for (i = 0; args.files[i]; i++) {
if ((f = fopen(args.files[i], "rb"))) {
if (!shaFile(args.files[i], f, which))
failure = 1;
fclose(f);
}
else {
fprintf(stderr, "%s: %s\n",args.files[i], "No such file or directory");
failure = 1;
}
}
exit(failure);
}