changeset 152:250d172662ca

fc-simtool a38 command: use generalized hex string parsing function
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Feb 2021 00:23:06 +0000
parents d515cfbb3f39
children a63e4c64f1f0
files simtool/a38.c
diffstat 1 files changed, 1 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/a38.c	Sun Feb 07 00:18:30 2021 +0000
+++ b/simtool/a38.c	Sun Feb 07 00:23:06 2021 +0000
@@ -11,39 +11,6 @@
 #include <winscard.h>
 #include "globals.h"
 
-static
-hexarg_16bytes(arg, databuf)
-	char *arg;
-	u_char *databuf;
-{
-	unsigned count;
-
-	for (count = 0; ; count++) {
-		while (isspace(*arg))
-			arg++;
-		if (!*arg)
-			break;
-		if (!isxdigit(arg[0]) || !isxdigit(arg[1])) {
-			fprintf(stderr, "error: invalid hex string input\n");
-			return(-1);
-		}
-		if (count >= 16) {
-			fprintf(stderr,
-			"error: hex string is longer than required 16 bytes\n");
-			return(-1);
-		}
-		databuf[count] = (decode_hex_digit(arg[0]) << 4) |
-				 decode_hex_digit(arg[1]);
-		arg += 2;
-	}
-	if (count < 16) {
-		fprintf(stderr,
-		"error: hex string is shorter than required 16 bytes\n");
-		return(-1);
-	}
-	return(0);
-}
-
 cmd_a38(argc, argv)
 	char **argv;
 {
@@ -56,7 +23,7 @@
 	cmd[2] = 0;
 	cmd[3] = 0;
 	cmd[4] = 16;
-	rc = hexarg_16bytes(argv[1], cmd + 5);
+	rc = decode_hex_data_from_string(argv[1], cmd + 5, 16, 16);
 	if (rc < 0)
 		return(rc);
 	rc = apdu_exchange(cmd, 21);