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