PIV: refactor to use sc_compacttlv_find_tag()

This commit is contained in:
Peter Marschall 2018-06-09 10:15:13 +02:00 committed by Frank Morgner
parent 40b02b2582
commit f2ba0ad9be
1 changed files with 14 additions and 18 deletions

View File

@ -2985,9 +2985,7 @@ static int piv_match_card(sc_card_t *card)
static int piv_match_card_continued(sc_card_t *card) static int piv_match_card_continued(sc_card_t *card)
{ {
int i, i7e, k; int i, i7e;
size_t j;
u8 *p, *pe;
sc_file_t aidfile; sc_file_t aidfile;
int type = -1; int type = -1;
piv_private_data_t *priv = NULL; piv_private_data_t *priv = NULL;
@ -3042,23 +3040,21 @@ static int piv_match_card_continued(sc_card_t *card)
} }
else if (card->reader->atr_info.hist_bytes[0] == 0x80u) { /* compact TLV */ else if (card->reader->atr_info.hist_bytes[0] == 0x80u) { /* compact TLV */
p = card->reader->atr_info.hist_bytes; size_t datalen;
pe = p + card->reader->atr_info.hist_bytes_len; const u8 *data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
p++; /* skip 0x80u byte */ card->reader->atr_info.hist_bytes_len - 1,
while (p < pe && type == -1) { 0xF0, &datalen);
j = *p & 0x0fu; /* length */
if ((*p++ & 0xf0u) == 0xf0u) { /*looking for 15 */ if (data != NULL) {
if ((p + j) <= pe) { int k;
for (k = 0; piv_aids[k].len_long != 0; k++) {
if (j == piv_aids[k].len_long for (k = 0; piv_aids[k].len_long != 0; k++) {
&& !memcmp(p, piv_aids[k].value,j)) { if (datalen == piv_aids[k].len_long
type = SC_CARD_TYPE_PIV_II_HIST; && !memcmp(data, piv_aids[k].value, datalen)) {
break; type = SC_CARD_TYPE_PIV_II_HIST;
} break;
}
} }
} }
p += j;
} }
} }
} }