Replace private implemetation with interface.
[platform/core/security/key-manager.git] / src / manager / client / client-control.cpp
index 6d30c8a..e87658e 100644 (file)
 #include <message-buffer.h>
 #include <protocols.h>
 
-#include <ckm/key-manager.h>
+#include <ckm/ckm-control.h>
 
 namespace CKM {
 
-class Control::ControlImpl {
+class ControlImpl : public Control {
 public:
     ControlImpl(){}
     ControlImpl(const ControlImpl &) = delete;
@@ -36,22 +36,25 @@ public:
     ControlImpl& operator=(const ControlImpl &) = delete;
     ControlImpl& operator=(ControlImpl &&) = delete;
 
-    static int unlockUserKey(const std::string &user, const std::string &password) {
+    virtual int unlockUserKey(uid_t user, const std::string &password) const {
         return try_catch([&] {
-            if (user.empty())
-                return KEY_MANAGER_API_ERROR_INPUT_PARAM;
-
             MessageBuffer send, recv;
             Serialization::Serialize(send, static_cast<int>(ControlCommand::UNLOCK_USER_KEY));
             Serialization::Serialize(send, user);
             Serialization::Serialize(send, password);
+            int retCode;
+
+            if((int)user < 0) {
+                retCode = CKM_API_ERROR_INPUT_PARAM;
+                return retCode;
+            }
 
-            int retCode = sendToServer(
+            retCode = sendToServer(
                 SERVICE_SOCKET_CKM_CONTROL,
                 send.Pop(),
                 recv);
 
-            if (KEY_MANAGER_API_SUCCESS != retCode) {
+            if (CKM_API_SUCCESS != retCode) {
                 return retCode;
             }
 
@@ -61,21 +64,24 @@ public:
         });
     }
 
-    static int lockUserKey(const std::string &user) {
+    virtual int lockUserKey(uid_t user) const {
         return try_catch([&] {
-            if (user.empty())
-                return KEY_MANAGER_API_ERROR_INPUT_PARAM;
-
             MessageBuffer send, recv;
             Serialization::Serialize(send, static_cast<int>(ControlCommand::LOCK_USER_KEY));
             Serialization::Serialize(send, user);
+            int retCode;
+
+            if((int)user < 0) {
+                retCode = CKM_API_ERROR_INPUT_PARAM;
+                return retCode;
+            }
 
-            int retCode = sendToServer(
+            retCode = sendToServer(
                 SERVICE_SOCKET_CKM_CONTROL,
                 send.Pop(),
                 recv);
 
-            if (KEY_MANAGER_API_SUCCESS != retCode) {
+            if (CKM_API_SUCCESS != retCode) {
                 return retCode;
             }
 
@@ -85,21 +91,24 @@ public:
         });
     }
 
-    static int removeUserData(const std::string &user) {
+    virtual int removeUserData(uid_t user) const {
         return try_catch([&] {
-            if (user.empty())
-                return KEY_MANAGER_API_ERROR_INPUT_PARAM;
-
             MessageBuffer send, recv;
             Serialization::Serialize(send, static_cast<int>(ControlCommand::REMOVE_USER_DATA));
             Serialization::Serialize(send, user);
+            int retCode;
+
+            if((int)user < 0) {
+                retCode = CKM_API_ERROR_INPUT_PARAM;
+                return retCode;
+            }
 
-            int retCode = sendToServer(
+            retCode = sendToServer(
                 SERVICE_SOCKET_CKM_CONTROL,
                 send.Pop(),
                 recv);
 
-            if (KEY_MANAGER_API_SUCCESS != retCode) {
+            if (CKM_API_SUCCESS != retCode) {
                 return retCode;
             }
 
@@ -109,23 +118,26 @@ public:
         });
     }
 
-    static int changeUserPassword(const std::string &user, const std::string &oldPassword, const std::string &newPassword) {
+    virtual int changeUserPassword(uid_t user, const std::string &oldPassword, const std::string &newPassword) const {
         return try_catch([&] {
-            if (user.empty())
-                return KEY_MANAGER_API_ERROR_INPUT_PARAM;
-
             MessageBuffer send, recv;
             Serialization::Serialize(send, static_cast<int>(ControlCommand::CHANGE_USER_PASSWORD));
             Serialization::Serialize(send, user);
             Serialization::Serialize(send, oldPassword);
             Serialization::Serialize(send, newPassword);
+            int retCode;
+
+            if((int)user < 0) {
+                retCode = CKM_API_ERROR_INPUT_PARAM;
+                return retCode;
+            }
 
-            int retCode = sendToServer(
+            retCode = sendToServer(
                 SERVICE_SOCKET_CKM_CONTROL,
                 send.Pop(),
                 recv);
 
-            if (KEY_MANAGER_API_SUCCESS != retCode) {
+            if (CKM_API_SUCCESS != retCode) {
                 return retCode;
             }
 
@@ -135,22 +147,25 @@ public:
         });
     }
 
-    static int resetUserPassword(const std::string &user, const std::string &newPassword) {
+    virtual int resetUserPassword(uid_t user, const std::string &newPassword) const {
         return try_catch([&] {
-            if (user.empty())
-                return KEY_MANAGER_API_ERROR_INPUT_PARAM;
-
             MessageBuffer send, recv;
             Serialization::Serialize(send, static_cast<int>(ControlCommand::RESET_USER_PASSWORD));
             Serialization::Serialize(send, user);
             Serialization::Serialize(send, newPassword);
+            int retCode;
+
+            if((int)user < 0) {
+                retCode = CKM_API_ERROR_INPUT_PARAM;
+                return retCode;
+            }
 
-            int retCode = sendToServer(
+            retCode = sendToServer(
                 SERVICE_SOCKET_CKM_CONTROL,
                 send.Pop(),
                 recv);
 
-            if (KEY_MANAGER_API_SUCCESS != retCode) {
+            if (CKM_API_SUCCESS != retCode) {
                 return retCode;
             }
 
@@ -161,32 +176,11 @@ public:
     }
 
     virtual ~ControlImpl(){}
-};
-
-Control::Control()
-  : m_impl(new ControlImpl)
-{}
 
-Control::~Control(){}
-
-int Control::unlockUserKey(const std::string &user, const std::string &password) const {
-    return m_impl->unlockUserKey(user, password);
-}
-
-int Control::lockUserKey(const std::string &user) const {
-    return m_impl->lockUserKey(user);
-}
-
-int Control::removeUserData(const std::string &user) const {
-    return m_impl->removeUserData(user);
-}
-
-int Control::changeUserPassword(const std::string &user, const std::string &oldPassword, const std::string &newPassword) const {
-    return m_impl->changeUserPassword(user, oldPassword, newPassword);
-}
+};
 
-int Control::resetUserPassword(const std::string &user, const std::string &newPassword) const {
-    return m_impl->resetUserPassword(user, newPassword);
+ControlShPtr Control::create() {
+    return ControlShPtr(new ControlImpl());
 }
 
 } // namespace CKM