From 41c00903219be30f87d56db6ccc352f89a2df44a Mon Sep 17 00:00:00 2001 From: vtarasov Date: Tue, 18 Jan 2011 16:02:09 +0000 Subject: [PATCH] pkcs15: redesign sc_pkcs15_make_absolute_path() ... - do nothing if child has 'aid'; - child inherit the parents's 'aid' if this one exists; - child inherit parents's path of type 'DF NAME' as 'aid'; - return if child path is zero length; - finaly concatenate parent and child paths. git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5108 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/libopensc/pkcs15.c | 50 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/libopensc/pkcs15.c b/src/libopensc/pkcs15.c index d9c45094..d176d43e 100644 --- a/src/libopensc/pkcs15.c +++ b/src/libopensc/pkcs15.c @@ -2004,32 +2004,40 @@ int sc_pkcs15_hex_string_to_id(const char *in, struct sc_pkcs15_id *out) int sc_pkcs15_make_absolute_path(const sc_path_t *parent, sc_path_t *child) { - sc_path_t ppath; + /* nothing to do if child has valid 'aid' */ + if (child->aid.len) + return SC_SUCCESS; + + if (parent->aid.len) { + sc_path_t ppath; + + /* child inherits parent's 'aid' */ + child->aid = parent->aid; + if (!parent->len) + return SC_SUCCESS; + + /* parent has valid 'path' -- concatenate it with the child's one */ + memcpy(&ppath, parent, sizeof(sc_path_t)); + ppath.aid.len = 0; + ppath.type = SC_PATH_TYPE_FROM_CURRENT; + return sc_concatenate_path(child, &ppath, child); + + } + else if (parent->type == SC_PATH_TYPE_DF_NAME) { + /* child inherits parent's 'DF NAME' as 'aid' */ + if (parent->len > sizeof(child->aid.value)) + return SC_ERROR_WRONG_LENGTH; + + memcpy(child->aid.value, parent->value, parent->len); + child->aid.len = parent->len; + + return SC_SUCCESS; + } /* a 0 length path stays a 0 length path */ if (child->len == 0) return SC_SUCCESS; - if (child->aid.len) - return SC_SUCCESS; - - memcpy(&ppath, parent, sizeof(sc_path_t)); - if (ppath.aid.len) { - memcpy(&child->aid, &ppath.aid, sizeof(child->aid)); - if (ppath.len) { - ppath.aid.len = 0; - ppath.type = SC_PATH_TYPE_FROM_CURRENT; - return sc_concatenate_path(child, &ppath, child); - } - return SC_SUCCESS; - } - else if (ppath.type == SC_PATH_TYPE_DF_NAME) { - memcpy(child->aid.value, ppath.value, ppath.len); - child->aid.len = ppath.len; - - return SC_SUCCESS; - } - if (sc_compare_path_prefix(sc_get_mf_path(), child)) return SC_SUCCESS;