From af50278fc92ce5846d727eaa2b66b85063f53cae Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 15 Jan 2021 02:42:02 -0600 Subject: Cleanup base32 slightly. --- lib/lib.c | 12 ------------ lib/lib.h | 1 - toys/other/base64.c | 18 +++++++++--------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/lib/lib.c b/lib/lib.c index 1aa9b80d..dfa4499f 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -870,18 +870,6 @@ void base64_init(char *p) *(p++) = '/'; } -// Init base32 table - -void base32_init(char *p) -{ - int i; - - for (i = 'A'; i != '8'; i++) { - if (i == 'Z'+1) i = '2'; - *(p++) = i; - } -} - int yesno(int def) { return fyesno(stdin, def); diff --git a/lib/lib.h b/lib/lib.h index 1ba59ee3..431ce5ad 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -255,7 +255,6 @@ void delete_tempfile(int fdin, int fdout, char **tempname); void replace_tempfile(int fdin, int fdout, char **tempname); void crc_init(unsigned int *crc_table, int little_endian); void base64_init(char *p); -void base32_init(char *p); int yesno(int def); int fyesno(FILE *fp, int def); int qstrcmp(const void *a, const void *b); diff --git a/toys/other/base64.c b/toys/other/base64.c index 25e37d41..22652fd0 100644 --- a/toys/other/base64.c +++ b/toys/other/base64.c @@ -2,8 +2,9 @@ * * Copyright 2014 Rob Landley * - * No standard + * See https://tools.ietf.org/html/rfc4648 +// These optflags have to match. Todo: cleanup and collapse together? USE_BASE64(NEWTOY(base64, "diw#<0=76[!dw]", TOYFLAG_USR|TOYFLAG_BIN)) USE_BASE32(NEWTOY(base32, "diw#<0=76[!dw]", TOYFLAG_USR|TOYFLAG_BIN)) @@ -33,6 +34,7 @@ config BASE32 */ #define FOR_base64 +#define FORCE_FLAGS #include "toys.h" GLOBALS( @@ -52,7 +54,7 @@ static void wraputchar(int c, int *x) }; } -static void do_base_n(int fd, char *name) +static void do_base(int fd, char *name) { int out = 0, bits = 0, x = 0, i, len; char *buf = toybuf+128; @@ -106,17 +108,15 @@ void base64_main(void) TT.n = 6; TT.align = 3; base64_init(toybuf); - loopfiles(toys.optargs, do_base_n); + loopfiles(toys.optargs, do_base); } -#define CLEANUP_base64 -#define FOR_base32 -#include "generated/flags.h" - void base32_main(void) { + int i; + TT.n = 5; TT.align = 7; - base32_init(toybuf); - loopfiles(toys.optargs, do_base_n); + for (i = 0; i<32; i++) toybuf[i] = i+(i<26 ? 'A' : 24); + loopfiles(toys.optargs, do_base); } -- cgit v1.2.3