libopensc: cache EF.ODF and EF.TokenInfo

This commit is contained in:
Frank Morgner 2016-06-20 13:12:27 +02:00 committed by Viktor Tarasov
parent 60f2d06308
commit 21fd6f0d95
1 changed files with 41 additions and 17 deletions

View File

@ -1074,6 +1074,13 @@ sc_pkcs15_bind_internal(struct sc_pkcs15_card *p15card, struct sc_aid *aid)
if(buf == NULL)
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
err = -1; /* file state: not in cache */
if (p15card->opts.use_file_cache) {
err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
if (err == SC_SUCCESS)
err = len;
}
if (err < 0) {
err = sc_read_binary(card, 0, buf, len, 0);
if (err < 0) {
sc_log(ctx, "read EF(ODF) file error: %s", sc_strerror(err));
@ -1084,7 +1091,11 @@ sc_pkcs15_bind_internal(struct sc_pkcs15_card *p15card, struct sc_aid *aid)
sc_log(ctx, "Invalid content of EF(ODF): %s", sc_strerror(err));
goto end;
}
len = err;
if (p15card->opts.use_file_cache) {
sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
}
}
if (parse_odf(buf, len, p15card)) {
err = SC_ERROR_PKCS15_APP_NOT_FOUND;
@ -1129,6 +1140,13 @@ sc_pkcs15_bind_internal(struct sc_pkcs15_card *p15card, struct sc_aid *aid)
if(buf == NULL)
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
err = -1; /* file state: not in cache */
if (p15card->opts.use_file_cache) {
err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
if (err == SC_SUCCESS)
err = len;
}
if (err < 0) {
err = sc_read_binary(card, 0, buf, len, 0);
if (err < 0) {
sc_log(ctx, "read EF(TokenInfo) file error: %s", sc_strerror(err));
@ -1140,6 +1158,12 @@ sc_pkcs15_bind_internal(struct sc_pkcs15_card *p15card, struct sc_aid *aid)
goto end;
}
if (p15card->opts.use_file_cache) {
sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
}
err = len;
}
memset(&tokeninfo, 0, sizeof(tokeninfo));
err = sc_pkcs15_parse_tokeninfo(ctx, &tokeninfo, buf, (size_t)err);
if (err != SC_SUCCESS) {