From f3d6a71320fa76ebe7debc5690e56a5401f5701e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Thu, 28 Dec 2006 20:29:27 +0000 Subject: [PATCH] add hxtool_hex git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19541 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/hx509/hxtool.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/hx509/hxtool.c b/lib/hx509/hxtool.c index b97129305..b52afd7c0 100644 --- a/lib/hx509/hxtool.c +++ b/lib/hx509/hxtool.c @@ -1092,6 +1092,38 @@ crypto_select(struct crypto_select_options *opt, int argc, char **argv) return 0; } +int +hxtool_hex(struct hex_options *opt, int argc, char **argv) +{ + + if (opt->decode_flag) { + char buf[1024], buf2[1024], *p; + ssize_t len; + + while(fgets(buf, sizeof(buf), stdin) != NULL) { + buf[strcspn(buf, "\r\n")] = '\0'; + p = buf; + while(isspace(*(unsigned char *)p)) + p++; + len = hex_decode(p, buf2, strlen(p)); + if (len < 0) + errx(1, "hex_decode failed"); + if (fwrite(buf2, 1, len, stdout) != len) + errx(1, "fwrite failed"); + } + } else { + char buf[28], *p; + size_t len; + + while((len = fread(buf, 1, sizeof(buf), stdin)) != 0) { + len = hex_encode(buf, len, &p); + fprintf(stdout, "%s\n", p); + free(p); + } + } + return 0; +} + int help(void *opt, int argc, char **argv) {