view libutil/hexstr.c @ 93:6041c601304d

fcsim1-mkprov: revert OTA key addition It appears that GrcardSIM2 cards (which is what we got for FCSIM1) do not support OTA after all, contrary to what we were previously led to believe by some tech support emails from Grcard - apparently those support emails and OTA descriptions referred to some other card model(s).
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 21 Apr 2021 05:38:39 +0000
parents 34bbb0585cab
children
line wrap: on
line source

/*
 * This module contains the function for decoding hex strings.
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>

decode_hex_data_from_string(arg, databuf, minlen, maxlen)
	char *arg;
	u_char *databuf;
	unsigned minlen, maxlen;
{
	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 >= maxlen) {
			fprintf(stderr, "error: hex string is too long\n");
			return(-1);
		}
		databuf[count] = (decode_hex_digit(arg[0]) << 4) |
				 decode_hex_digit(arg[1]);
		arg += 2;
	}
	if (count < minlen) {
		fprintf(stderr, "error: hex string is too short\n");
		return(-1);
	}
	return(count);
}