scd:openpgp: Small speedup reading card properties.

* scd/app-openpgp.c (struct app_local_s): Add new flag.
(get_cached_data): Force chace use if flag is set.
(app_select_openpgp): Avoid reading DO 6E multiple times.
--

The do not cache property of 6E was introduced so that we can change
for example key attributes without getting into with the cache.
However, for initial reading the cache makes a lot of sense and thus we
now use this hack to only temporary cache.  A better strategy would be
to clear the cache when we change card data but that is more error
prone.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2021-03-19 13:43:46 +01:00
parent 85082a83c2
commit d5fb598323
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 18 additions and 2 deletions

View File

@ -218,6 +218,11 @@ struct app_local_s {
unsigned int def_chv2:1; /* Use 123456 for CHV2. */
} flags;
/* Flags used to override certain behavior. */
struct
{
unsigned int cache_6e:1;
} override;
/* Keep track on whether we cache a certain PIN so that we get it
* from the cache only if we know we cached it. This inhibits the
@ -405,6 +410,9 @@ get_cached_data (app_t app, int tag,
*result = NULL;
*resultlen = 0;
if (tag == 0x6E && app->app_local->override.cache_6e)
get_immediate = 0;
if (!get_immediate)
{
for (c=app->app_local->cache; c; c = c->next)
@ -6138,6 +6146,9 @@ app_select_openpgp (app_t app)
goto leave;
}
/* We want to temporary cache the DO 6E. */
app->app_local->override.cache_6e = 1;
app->app_local->manufacturer = manufacturer;
if (app->appversion >= 0x0200)
@ -6216,8 +6227,10 @@ app_select_openpgp (app_t app)
/* Check optional DO of "General Feature Management" for button. */
relptr = get_one_do (app, 0x7f74, &buffer, &buflen, NULL);
if (relptr)
/* It must be: 03 81 01 20 */
app->app_local->extcap.has_button = 1;
{
/* It must be: 03 81 01 20 */
app->app_local->extcap.has_button = 1;
}
parse_login_data (app);
@ -6231,6 +6244,9 @@ app_select_openpgp (app_t app)
if (opt.verbose > 1)
dump_all_do (slot);
app->app_local->override.cache_6e = 0;
flush_cache_item (app, 0x6E);
app->fnc.deinit = do_deinit;
app->fnc.prep_reselect = do_prep_reselect;
app->fnc.reselect = do_reselect;