Add app_exists() to check if an AID is loaded.

This commit is contained in:
Pol Henarejos 2025-05-25 19:07:20 +02:00
parent 11d8a5343c
commit eb75ad4efa
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
2 changed files with 16 additions and 0 deletions

View file

@ -33,6 +33,7 @@ typedef struct app {
int (*unload)();
} app_t;
extern bool app_exists(const uint8_t *aid, size_t aid_len);
extern int register_app(int (*)(app_t *, uint8_t), const uint8_t *);
extern int select_app(const uint8_t *aid, size_t aid_len);

View file

@ -54,7 +54,22 @@ app_t *current_app = NULL;
const uint8_t *ccid_atr = NULL;
bool app_exists(const uint8_t *aid, size_t aid_len) {
if (current_app && current_app->aid && (current_app->aid + 1 == aid || !memcmp(current_app->aid + 1, aid, aid_len))) {
return true;
}
for (int a = 0; a < num_apps; a++) {
if (!memcmp(apps[a].aid + 1, aid, MIN(aid_len, apps[a].aid[0]))) {
return true;
}
}
return false;
}
int register_app(int (*select_aid)(app_t *, uint8_t), const uint8_t *aid) {
if (app_exists(aid + 1, aid[0])) {
return 1;
}
if (num_apps < sizeof(apps) / sizeof(app_t)) {
apps[num_apps].select_aid = select_aid;
apps[num_apps].aid = aid;