From 731d7284da22e5040348086dc9de5dd600cab21c Mon Sep 17 00:00:00 2001 From: Przemyslaw Ciezkowski Date: Mon, 27 Apr 2015 14:00:38 +0200 Subject: [PATCH] [KeyManager] removeKey implementation [Verification] var myPubKey = new tizen.Key("pub1", null, true); myPubKey.save("rawData", function() { myPubKey.remove(); }, function(e) { console.log("error: " + e.message); }); Signed-off-by: Przemyslaw Ciezkowski Change-Id: I396c756024d1d9123ad34c01324806e2dee2733c --- src/keymanager/keymanager_instance.cc | 22 ++++++++++++++++++++++ src/keymanager/keymanager_instance.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/keymanager/keymanager_instance.cc b/src/keymanager/keymanager_instance.cc index 106d1c4..8c6022e 100644 --- a/src/keymanager/keymanager_instance.cc +++ b/src/keymanager/keymanager_instance.cc @@ -25,6 +25,8 @@ KeyManagerInstance::KeyManagerInstance() { std::bind(&KeyManagerInstance::GetKeyAliasList, this, _1, _2)); RegisterSyncHandler("KeyManager_saveKey", std::bind(&KeyManagerInstance::SaveKey, this, _1, _2)); + RegisterSyncHandler("KeyManager_removeKey", + std::bind(&KeyManagerInstance::RemoveKey, this, _1, _2)); } KeyManagerInstance::~KeyManagerInstance() { @@ -92,5 +94,25 @@ void KeyManagerInstance::OnSaveKey(double callbackId, PostMessage(res.serialize().c_str()); } +void KeyManagerInstance::RemoveKey(const picojson::value& args, + picojson::object& out) { + LoggerD("Enter"); + + const std::string& alias = args.get("key").get("name").get(); + int ret = CKM::Manager::create()->removeAlias(alias); + if (ret != CKM_API_SUCCESS) { + LoggerE("Failed to remove key alias: %d", ret); + if (ret == CKM_API_ERROR_DB_ALIAS_UNKNOWN) { + ReportError(common::PlatformResult(common::ErrorCode::NOT_FOUND_ERR, + "Key alias not found"), &out); + } else { + ReportError(common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, + "Failed to remove key alias"), &out); + } + } else { + ReportSuccess(out); + } +} + } // namespace keymanager } // namespace extension diff --git a/src/keymanager/keymanager_instance.h b/src/keymanager/keymanager_instance.h index 517f0b4..1d9f0b6 100644 --- a/src/keymanager/keymanager_instance.h +++ b/src/keymanager/keymanager_instance.h @@ -23,6 +23,7 @@ class KeyManagerInstance : private: void GetKeyAliasList(picojson::value const& args, picojson::object& out); void SaveKey(const picojson::value& args, picojson::object& out); + void RemoveKey(const picojson::value& args, picojson::object& out); CKM::ManagerAsync m_manager; }; -- 2.7.4