OpenPGP: re-factor pgp_select_file()
* remove unnecessary copy operations with a temporary path object, instead increase the start index. * addd comments Signed-off-by: Peter Marschall <peter@adpm.de> git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5489 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
4a3df98450
commit
cf3a34cbef
|
@ -460,14 +460,11 @@ pgp_select_file(sc_card_t *card, const sc_path_t *path, sc_file_t **ret)
|
||||||
{
|
{
|
||||||
struct pgp_priv_data *priv = DRVDATA(card);
|
struct pgp_priv_data *priv = DRVDATA(card);
|
||||||
struct blob *blob;
|
struct blob *blob;
|
||||||
sc_path_t path_copy;
|
unsigned int path_start;
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
int r;
|
|
||||||
|
|
||||||
LOG_FUNC_CALLED(card->ctx);
|
LOG_FUNC_CALLED(card->ctx);
|
||||||
|
|
||||||
memset(&path_copy, 0, sizeof(path_copy));
|
|
||||||
|
|
||||||
if (path->type == SC_PATH_TYPE_DF_NAME)
|
if (path->type == SC_PATH_TYPE_DF_NAME)
|
||||||
LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, path, ret));
|
LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, path, ret));
|
||||||
|
|
||||||
|
@ -479,24 +476,23 @@ pgp_select_file(sc_card_t *card, const sc_path_t *path, sc_file_t **ret)
|
||||||
LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
|
LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
|
||||||
"invalid path length");
|
"invalid path length");
|
||||||
|
|
||||||
if (!memcmp(path->value, "\x3f\x00", 2)) {
|
/* ignore explicitely mentioned MF at the path's beginning */
|
||||||
memcpy(path_copy.value, path->value + 2, path->len - 2);
|
path_start = (memcmp(path->value, "\x3f\x00", 2) == 0) ? 2 : 0;
|
||||||
path_copy.len = path->len - 2;
|
|
||||||
path = &path_copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* starting with the MF ... */
|
||||||
blob = priv->mf;
|
blob = priv->mf;
|
||||||
for (n = 0; n < path->len; n += 2) {
|
/* ... recurse through the tree following the path */
|
||||||
r = pgp_get_blob(card, blob,
|
for (n = path_start; n < path->len; n += 2) {
|
||||||
(path->value[n] << 8) | path->value[n+1],
|
unsigned int id = bebytes2ushort(path->value + n);
|
||||||
&blob);
|
int r = pgp_get_blob(card, blob, id, &blob);
|
||||||
if (r < 0) {
|
|
||||||
|
if (r < 0) { /* failure */
|
||||||
priv->current = NULL;
|
priv->current = NULL;
|
||||||
LOG_FUNC_RETURN(card->ctx, r);
|
LOG_FUNC_RETURN(card->ctx, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* select file = set "current" pointer to blob found */
|
/* success: select file = set "current" pointer to blob found */
|
||||||
priv->current = blob;
|
priv->current = blob;
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|
Loading…
Reference in New Issue