1
0
mirror of git://git.suckless.org/sbase synced 2024-12-22 15:04:53 +00:00
sbase/sha256sum.c
FRIGN 9b06720f62 Refactor cryptcheck() to allow multiple list-files and stdin
Previously, it was not possible to use

sha1sum test.c | sha1sum -c

because the program would not differenciate between an empty
argument and a non-specified argument.
Moreover, why not allow this?

sha1sum -c hashlist1 hashlist2

Digging deeper I found that using function pointers and a
modification in the crypt-backend might simplify the program
a lot by passing the argument-list to both cryptmain and
cryptcheck.
Allowing more than one list-file to be specified is also
consistent with what the other implementations support,
so we not only have simpler code, we also do not silently
break if there's a script around passing multiple files to
check.
2015-03-01 22:51:52 +01:00

39 lines
649 B
C

/* See LICENSE file for copyright and license details. */
#include <stdint.h>
#include <stdio.h>
#include "crypt.h"
#include "sha256.h"
#include "util.h"
static struct sha256 s;
struct crypt_ops sha256_ops = {
sha256_init,
sha256_update,
sha256_sum,
&s,
};
static void
usage(void)
{
eprintf("usage: %s [-c] [file ...]\n", argv0);
}
int
main(int argc, char *argv[])
{
int (*cryptfunc)(int, char **, struct crypt_ops *, uint8_t *, size_t) = cryptmain;
uint8_t md[SHA256_DIGEST_LENGTH];
ARGBEGIN {
case 'c':
cryptfunc = cryptcheck;
break;
default:
usage();
} ARGEND;
return cryptfunc(argc, argv, &sha256_ops, md, sizeof(md));
}