From 2ae8b90be07686640c4115b0760fde7fd315bb6d Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Fri, 29 Jul 2016 09:24:49 +0900 Subject: [PATCH] [CAPI added] ckmc_alias_new() Make full alias with owner id and data alias (and separator between them) Change-Id: I103d3ca0577c6847df65a402907b12b388a8e49e Signed-off-by: Kyungwook Tak --- src/include/ckmc/ckmc-type.h | 53 +++++++++++++++++++++++++++++------ src/manager/client-capi/ckmc-type.cpp | 21 ++++++++++++++ 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/include/ckmc/ckmc-type.h b/src/include/ckmc/ckmc-type.h index b14b413..4089b4e 100644 --- a/src/include/ckmc/ckmc-type.h +++ b/src/include/ckmc/ckmc-type.h @@ -43,15 +43,15 @@ extern "C" { * Preinstalled system(uid < 5000) and user (uid >= 5000) applications * does not have any pkgId. Thats why ckm uses special "virtual" * pkgid for them. The virtual strings are defined under: - * ckmc_ownerid_system - * ckmc_ownerid_user - * + * ckmc_owner_id_system */ /** * @deprecated Deprecated since 3.0. [Use ckmc_owner_id_separator instead] * @brief Separator between alias and label. + * * @since_tizen 2.3 + * * @remarks Alias can be provided as an alias alone, or together with label - in this * case, separator " " (space bar) is used to separate label and alias. * @@ -62,21 +62,29 @@ KEY_MANAGER_CAPI extern char const *const ckmc_label_name_separator; /** * @brief Separator between alias and owner id. + * * @since_tizen 3.0 + * * @remarks Alias can be provided as an alias alone, or together with owner id. * In this case, separator " " (space bar) is used to separate id and alias. + * + * @see ckmc_alias_new() * @see key-manager_doc.h */ KEY_MANAGER_CAPI extern char const *const ckmc_owner_id_separator; /** * @brief The owner of system database. + * * @since_tizen 3.0 - * @remarks ckmc_owner_id_system constains id connected with all SYSTEM applications that run - * with uid less than 5000. - * Client should use ckmc_owner_id_system to access data owned by system application - * and stored in system database. - * Note: Client must have permission to access proper row. + * + * @remarks @a ckmc_owner_id_system constains id connected with all system applications + * that run with uid less than 5000. + * @remarks Client should use @a ckmc_owner_id_system to access data owned by system + * application and stored in system database. + * @remarks Client must have permission to access proper row. + * + * @see ckmc_alias_new() */ KEY_MANAGER_CAPI extern char const *const ckmc_owner_id_system; @@ -324,6 +332,35 @@ typedef enum __ckmc_algo_type { } ckmc_algo_type_e; /** + * @brief Creates a new full alias which is a concatenation of @a owner_id and @a alias. + * + * @since_tizen 3.0 + * + * @remarks @a full_alias should be freed with free() after use. + * @remarks Returns #CKMC_ERROR_INVALID_PARAMETER if any of parameter is NULL. + * @remarks Returns #CKMC_ERROR_INVALID_PARAMETER if @a owner_id is empty. + * + * @param[in] owner_id Data owner's id. This should be package id if data owner is + * application. If you want to access data stored by system + * services, it should be @a ckmc_owner_id_system + * @param[in] alias Data alias + * @param[out] full_alias The newly created alias which is a concatenation of + * @a owner_id, @a ckmc_owner_id_separator and @a alias. + * Destroy by free() after use + * + * @return #CKMC_ERROR_NONE on success, otherwise a negative error value + * + * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid + * @retval #CKMC_ERROR_OUT_OF_MEMORY Not enough memory + * + * @see #ckmc_owner_id_separator + * @see #ckmc_owner_id_system + * @see key-manager_doc.h + */ +int ckmc_alias_new(const char *owner_id, const char *alias, char **full_alias); + +/** * @brief Creates a new @a ckmc_key_s handle and returns it. * * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif diff --git a/src/manager/client-capi/ckmc-type.cpp b/src/manager/client-capi/ckmc-type.cpp index cadc56d..e6e020f 100644 --- a/src/manager/client-capi/ckmc-type.cpp +++ b/src/manager/client-capi/ckmc-type.cpp @@ -71,6 +71,27 @@ const char *const ckmc_owner_id_separator = CKM::LABEL_NAME_SEPARATOR; const char *const ckmc_owner_id_system = CKM::OWNER_ID_SYSTEM; KEY_MANAGER_CAPI +int ckmc_alias_new(const char *owner_id, const char *alias, char **full_alias) +{ + if (owner_id == NULL || alias == NULL || full_alias == NULL) + return CKMC_ERROR_INVALID_PARAMETER; + + size_t len = strlen(owner_id) + strlen(alias) + strlen(ckmc_owner_id_separator); + char *_full_alias = static_cast(malloc(len + 1)); + + if (_full_alias == NULL) + return CKMC_ERROR_OUT_OF_MEMORY; + + strcpy(_full_alias, owner_id); + strcat(_full_alias, ckmc_owner_id_separator); + strcat(_full_alias, alias); + + *full_alias = _full_alias; + + return CKMC_ERROR_NONE; +} + +KEY_MANAGER_CAPI int ckmc_key_new(unsigned char *raw_key, size_t key_size, ckmc_key_type_e key_type, char *password, ckmc_key_s **ppkey) { -- 2.7.4