FreeCalypso > hg > freecalypso-hwlab
comparison uicc/hexstr.c @ 138:baf5bd698764
fc-uicc-tool: select-aid command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 04 Feb 2021 04:51:08 +0000 |
parents | |
children | 65a2a96386cd |
comparison
equal
deleted
inserted
replaced
137:c331560c15a4 | 138:baf5bd698764 |
---|---|
1 /* | |
2 * This module contains the function for decoding hex strings. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <ctype.h> | |
7 #include <string.h> | |
8 #include <strings.h> | |
9 #include <stdio.h> | |
10 #include <stdlib.h> | |
11 | |
12 decode_hex_digit(c) | |
13 { | |
14 if (c >= '0' && c <= '9') | |
15 return(c - '0'); | |
16 if (c >= 'A' && c <= 'F') | |
17 return(c - 'A' + 10); | |
18 if (c >= 'a' && c <= 'f') | |
19 return(c - 'a' + 10); | |
20 return(-1); | |
21 } | |
22 | |
23 decode_hex_data_from_string(arg, databuf, maxlen) | |
24 char *arg; | |
25 u_char *databuf; | |
26 unsigned maxlen; | |
27 { | |
28 unsigned count; | |
29 | |
30 for (count = 0; ; count++) { | |
31 while (isspace(*arg)) | |
32 arg++; | |
33 if (!*arg) | |
34 break; | |
35 if (!isxdigit(arg[0]) || !isxdigit(arg[1])) { | |
36 fprintf(stderr, "error: invalid hex string input\n"); | |
37 return(-1); | |
38 } | |
39 if (count >= maxlen) { | |
40 fprintf(stderr, "error: hex input data is too long\n"); | |
41 return(-1); | |
42 } | |
43 databuf[count] = (decode_hex_digit(arg[0]) << 4) | | |
44 decode_hex_digit(arg[1]); | |
45 arg += 2; | |
46 } | |
47 if (!count) { | |
48 fprintf(stderr, "error: empty hex string argument\n"); | |
49 return(-1); | |
50 } | |
51 return(count); | |
52 } |