annotate libcommon/pinentry.c @ 126:7faec607500f

rehab-{imsi,loci} commands implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 20 Feb 2021 19:37:52 +0000
parents e9e8ce12f5a5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <ctype.h>
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdio.h>
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 encode_pin_entry(arg, dest)
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 char *arg;
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 u_char *dest;
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 {
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 unsigned n;
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 n = 0;
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 while (*arg) {
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 if (!isdigit(*arg)) {
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 fprintf(stderr,
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 "error: PIN argument contains a non-digit character\n");
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 return(-1);
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 }
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 if (n >= 8) {
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 fprintf(stderr, "error: PIN argument is too long\n");
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 return(-1);
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 }
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 *dest++ = *arg++;
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 n++;
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 for (; n < 8; n++)
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 *dest++ = 0xFF;
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(0);
e9e8ce12f5a5 encode_pin_entry() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }