pkcs15init: file 'content' and 'prop-attrs' in the card profile
Now it's possible to describe in the card profile the 'prop-attr' and 'encoded-content' data of the file to create
This commit is contained in:
parent
51262f00ac
commit
13d1b8e9f2
|
@ -97,6 +97,7 @@ sc_file_new
|
|||
sc_file_set_prop_attr
|
||||
sc_file_set_sec_attr
|
||||
sc_file_set_type_attr
|
||||
sc_file_set_content
|
||||
sc_file_valid
|
||||
sc_format_apdu
|
||||
sc_bytes2apdu
|
||||
|
|
|
@ -1139,6 +1139,8 @@ int sc_file_set_prop_attr(sc_file_t *file, const u8 *prop_attr,
|
|||
size_t prop_attr_len);
|
||||
int sc_file_set_type_attr(sc_file_t *file, const u8 *type_attr,
|
||||
size_t type_attr_len);
|
||||
int sc_file_set_content(sc_file_t *file, const u8 *content,
|
||||
size_t content_len);
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
|
|
|
@ -562,6 +562,8 @@ void sc_file_dup(sc_file_t **dest, const sc_file_t *src)
|
|||
goto err;
|
||||
if (sc_file_set_type_attr(newf, src->type_attr, src->type_attr_len) < 0)
|
||||
goto err;
|
||||
if (sc_file_set_content(newf, src->encoded_content, src->encoded_content_len) < 0)
|
||||
goto err;
|
||||
return;
|
||||
err:
|
||||
if (newf != NULL)
|
||||
|
@ -653,6 +655,38 @@ int sc_file_set_type_attr(sc_file_t *file, const u8 *type_attr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int sc_file_set_content(sc_file_t *file, const u8 *content,
|
||||
size_t content_len)
|
||||
{
|
||||
u8 *tmp;
|
||||
assert(sc_file_valid(file));
|
||||
|
||||
if (content == NULL) {
|
||||
if (file->encoded_content != NULL)
|
||||
free(file->encoded_content);
|
||||
file->encoded_content = NULL;
|
||||
file->encoded_content_len = 0;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
tmp = (u8 *) realloc(file->encoded_content, content_len);
|
||||
if (!tmp) {
|
||||
if (file->encoded_content)
|
||||
free(file->encoded_content);
|
||||
file->encoded_content = NULL;
|
||||
file->encoded_content_len = 0;
|
||||
return SC_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
file->encoded_content = tmp;
|
||||
memcpy(file->encoded_content, content, content_len);
|
||||
file->encoded_content_len = content_len;
|
||||
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int sc_file_valid(const sc_file_t *file) {
|
||||
#ifndef NDEBUG
|
||||
assert(file != NULL);
|
||||
|
|
|
@ -1348,6 +1348,36 @@ do_reclength(struct state *cur, int argc, char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
do_content(struct state *cur, int argc, char **argv)
|
||||
{
|
||||
struct sc_file *file = cur->file->file;
|
||||
size_t len = (strlen(argv[0]) + 1) / 2;
|
||||
int rv = 0;
|
||||
|
||||
file->encoded_content = malloc(len);
|
||||
if (!file->encoded_content)
|
||||
return 1;
|
||||
rv = sc_hex_to_bin(argv[0], file->encoded_content, &len);
|
||||
file->encoded_content_len = len;
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int
|
||||
do_prop_attr(struct state *cur, int argc, char **argv)
|
||||
{
|
||||
struct sc_file *file = cur->file->file;
|
||||
size_t len = (strlen(argv[0]) + 1) / 2;
|
||||
int rv = 0;
|
||||
|
||||
file->prop_attr = malloc(len);
|
||||
if (!file->prop_attr)
|
||||
return 1;
|
||||
rv = sc_hex_to_bin(argv[0], file->prop_attr, &len);
|
||||
file->prop_attr_len = len;
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int
|
||||
do_aid(struct state *cur, int argc, char **argv)
|
||||
{
|
||||
|
@ -1765,6 +1795,8 @@ static struct command fs_commands[] = {
|
|||
{ "profile-extension", 1, 1, do_profile_extension },
|
||||
/* AID of the DFs without file-id */
|
||||
{ "exclusive-aid", 1, 1, do_exclusive_aid },
|
||||
{ "content", 1, 1, do_content },
|
||||
{ "prop-attr", 1, 1, do_prop_attr },
|
||||
|
||||
{ NULL, 0, 0, NULL }
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue