pkcs15init: profile: new function 'get_parent' ...

to get profile instance of the parent of some file presented by it's profile name.

;accept hexadecimal values presented in 'xAB' form;
;coding style issues;


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5098 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
vtarasov 2011-01-17 15:51:47 +00:00
parent 1519cb38a1
commit c65bc9023b
2 changed files with 38 additions and 27 deletions

View File

@ -1985,6 +1985,24 @@ sc_profile_find_file_by_path(struct sc_profile *pro, const sc_path_t *path)
return out;
}
int
sc_profile_get_parent(struct sc_profile *profile,
const char *name, sc_file_t **ret)
{
struct file_info *fi = NULL;
if ((fi = sc_profile_find_file(profile, NULL, name)) == NULL)
return SC_ERROR_FILE_NOT_FOUND;
if (!fi->parent)
return SC_ERROR_FILE_NOT_FOUND;
sc_file_dup(ret, fi->parent->file);
if (*ret == NULL)
return SC_ERROR_OUT_OF_MEMORY;
return 0;
}
/*
* Split up KEY0 or CHV1 into SC_AC_XXX and a number
*/
@ -2000,7 +2018,7 @@ get_authid(struct state *cur, const char *value,
return get_uint(cur, value, type);
}
n = strcspn(value, "0123456789");
n = strcspn(value, "0123456789x");
strlcpy(temp, value, (sizeof(temp) > n) ? n + 1 : sizeof(temp));
if (map_str2int(cur, temp, type, aclNames))
@ -2018,6 +2036,8 @@ get_uint(struct state *cur, const char *value, unsigned int *vp)
if (strstr(value, "0x") == value)
*vp = strtoul(value + 2, &ep, 16);
else if (strstr(value, "x") == value)
*vp = strtoul(value + 1, &ep, 16);
else
*vp = strtoul(value, &ep, 0);
if (*ep != '\0') {

View File

@ -127,32 +127,23 @@ struct sc_profile {
};
struct sc_profile *sc_profile_new(void);
int sc_profile_load(struct sc_profile *, const char *);
int sc_profile_finish(struct sc_profile *, const struct sc_app_info *);
void sc_profile_free(struct sc_profile *);
int sc_profile_build_pkcs15(struct sc_profile *);
void sc_profile_get_pin_info(struct sc_profile *,
int, struct sc_pkcs15_pin_info *);
int sc_profile_get_pin_id(struct sc_profile *,
unsigned int, int *);
int sc_profile_get_file(struct sc_profile *, const char *,
struct sc_file **);
int sc_profile_get_file_by_path(struct sc_profile *,
const struct sc_path *, struct sc_file **);
int sc_profile_get_path(struct sc_profile *,
const char *, struct sc_path *);
int sc_profile_get_file_in(struct sc_profile *,
const sc_path_t *, const char *, sc_file_t **);
int sc_profile_instantiate_template(struct sc_profile *,
const char *, const sc_path_t *,
const char *, const sc_pkcs15_id_t *,
sc_file_t **);
int sc_profile_add_file(struct sc_profile *,
const char *, sc_file_t *);
int sc_profile_get_file_instance(struct sc_profile *, const char *,
int, sc_file_t **);
int sc_profile_get_pin_id_by_reference(struct sc_profile *,
unsigned, int, struct sc_pkcs15_pin_info *);
int sc_profile_load(struct sc_profile *, const char *);
int sc_profile_finish(struct sc_profile *, const struct sc_app_info *);
void sc_profile_free(struct sc_profile *);
int sc_profile_build_pkcs15(struct sc_profile *);
void sc_profile_get_pin_info(struct sc_profile *, int, struct sc_pkcs15_pin_info *);
int sc_profile_get_pin_id(struct sc_profile *, unsigned int, int *);
int sc_profile_get_file(struct sc_profile *, const char *, struct sc_file **);
int sc_profile_get_file_by_path(struct sc_profile *, const struct sc_path *, struct sc_file **);
int sc_profile_get_path(struct sc_profile *, const char *, struct sc_path *);
int sc_profile_get_file_in(struct sc_profile *, const sc_path_t *, const char *, sc_file_t **);
int sc_profile_instantiate_template(struct sc_profile *, const char *, const sc_path_t *,
const char *, const sc_pkcs15_id_t *, sc_file_t **);
int sc_profile_add_file(struct sc_profile *, const char *, sc_file_t *);
int sc_profile_get_file_instance(struct sc_profile *, const char *, int, sc_file_t **);
int sc_profile_get_pin_id_by_reference(struct sc_profile *, unsigned, int,
struct sc_pkcs15_pin_info *);
int sc_profile_get_parent(struct sc_profile *profile, const char *, sc_file_t **);
#ifdef __cplusplus
}