mirror of https://github.com/dirtbags/moth.git
Nicer argument parsing in tea
This commit is contained in:
parent
7b5a4e58b3
commit
64f7754800
|
@ -1,4 +1,4 @@
|
||||||
TARGETS = bubblebabble arc4
|
TARGETS = bubblebabble arc4 tea
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
||||||
|
|
33
src/tea.c
33
src/tea.c
|
@ -16,27 +16,40 @@
|
||||||
|
|
||||||
#define min(a,b) (((a)<(b))?(a):(b))
|
#define min(a,b) (((a)<(b))?(a):(b))
|
||||||
|
|
||||||
int
|
|
||||||
usage(const char *prog)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Usage: %s [-e] <PLAINTEXT\n", prog);
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
fprintf(stderr, "You must pass in a key on fd 3 or in the environment variable KEY.\n");
|
|
||||||
return EX_USAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
uint32_t key[4] = {0};
|
uint32_t key[4] = {0};
|
||||||
|
int encode = 0;
|
||||||
|
|
||||||
|
/* Parse args */
|
||||||
|
{
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "e")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'e':
|
||||||
|
encode = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Usage: %s [-e] <PLAINTEXT\n", argv[0]);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
fprintf(stderr, "You must pass in a key on fd 3 or in the environment variable KEY.\n");
|
||||||
|
return EX_USAGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read key */
|
||||||
{
|
{
|
||||||
char *ekey = getenv("KEY");
|
char *ekey = getenv("KEY");
|
||||||
|
|
||||||
if (ekey) {
|
if (ekey) {
|
||||||
memcpy(key, ekey, min(strlen(ekey), sizeof(key)));
|
size_t l = strlen(ekey);
|
||||||
|
|
||||||
|
memcpy(key, ekey, min(l, sizeof(key)));
|
||||||
} else {
|
} else {
|
||||||
read(3, key, sizeof(key));
|
read(3, key, sizeof(key));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue