master xplshn/aruu / cmd / pseudo / sha1sum.c
 1/* See LICENSE file for copyright and license details. */
 2
 3#include <stdint.h>
 4#include <stdio.h>
 5
 6#include "crypt.h"
 7#include "sha1.h"
 8#include "util.h"
 9
10static struct sha1 s;
11struct crypt_ops   sha1_ops = {
12    sha1_init,
13    sha1_update,
14    sha1_sum,
15    &s,
16};
17
18static void
19usage(void)
20{
21  eprintf("usage: %s [-c] [file ...]\n", argv0);
22}
23
24// ?man sha1sum: compute sha1 checksums
25// ?man arguments: file ...
26// ?man compute and check sha1 message digests
27int
28main(int argc, char *argv[])
29{
30  int     ret = 0, (*cryptfunc)(int, char **, struct crypt_ops *, uint8_t *, size_t) = cryptmain;
31  uint8_t md[SHA1_DIGEST_LENGTH];
32
33  ARGBEGIN
34  {
35    // ?man -b: specify block size or base directory
36    case 'b':
37    // ?man -t: sort or specify timestamp
38    case 't':
39      /* ignore */
40      break;
41    // ?man -c: print count or perform stdout action
42    case 'c':
43      cryptfunc = cryptcheck;
44      break;
45    default:
46      usage();
47  }
48  ARGEND
49
50  ret |= cryptfunc(argc, argv, &sha1_ops, md, sizeof(md));
51  ret |= fshut(stdin, "<stdin>") | fshut(stdout, "<stdout>");
52
53  return ret;
54}