Replace private implemetation with interface.
[platform/core/security/key-manager.git] / src / manager / client / client-control.cpp
index 1a352ff..e87658e 100644 (file)
@@ -28,7 +28,7 @@
 
 namespace CKM {
 
-class Control::ControlImpl {
+class ControlImpl : public Control {
 public:
     ControlImpl(){}
     ControlImpl(const ControlImpl &) = delete;
@@ -36,14 +36,20 @@ public:
     ControlImpl& operator=(const ControlImpl &) = delete;
     ControlImpl& operator=(ControlImpl &&) = delete;
 
-    static int unlockUserKey(uid_t user, const std::string &password) {
+    virtual int unlockUserKey(uid_t user, const std::string &password) const {
         return try_catch([&] {
             MessageBuffer send, recv;
             Serialization::Serialize(send, static_cast<int>(ControlCommand::UNLOCK_USER_KEY));
             Serialization::Serialize(send, user);
             Serialization::Serialize(send, password);
+            int retCode;
 
-            int retCode = sendToServer(
+            if((int)user < 0) {
+                retCode = CKM_API_ERROR_INPUT_PARAM;
+                return retCode;
+            }
+
+            retCode = sendToServer(
                 SERVICE_SOCKET_CKM_CONTROL,
                 send.Pop(),
                 recv);
@@ -58,13 +64,19 @@ public:
         });
     }
 
-    static int lockUserKey(uid_t user) {
+    virtual int lockUserKey(uid_t user) const {
         return try_catch([&] {
             MessageBuffer send, recv;
             Serialization::Serialize(send, static_cast<int>(ControlCommand::LOCK_USER_KEY));
             Serialization::Serialize(send, user);
+            int retCode;
 
-            int retCode = sendToServer(
+            if((int)user < 0) {
+                retCode = CKM_API_ERROR_INPUT_PARAM;
+                return retCode;
+            }
+
+            retCode = sendToServer(
                 SERVICE_SOCKET_CKM_CONTROL,
                 send.Pop(),
                 recv);
@@ -79,13 +91,19 @@ public:
         });
     }
 
-    static int removeUserData(uid_t user) {
+    virtual int removeUserData(uid_t user) const {
         return try_catch([&] {
             MessageBuffer send, recv;
             Serialization::Serialize(send, static_cast<int>(ControlCommand::REMOVE_USER_DATA));
             Serialization::Serialize(send, user);
+            int retCode;
 
-            int retCode = sendToServer(
+            if((int)user < 0) {
+                retCode = CKM_API_ERROR_INPUT_PARAM;
+                return retCode;
+            }
+
+            retCode = sendToServer(
                 SERVICE_SOCKET_CKM_CONTROL,
                 send.Pop(),
                 recv);
@@ -100,15 +118,21 @@ public:
         });
     }
 
-    static int changeUserPassword(uid_t 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([&] {
             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);
@@ -123,14 +147,20 @@ public:
         });
     }
 
-    static int resetUserPassword(uid_t user, const std::string &newPassword) {
+    virtual int resetUserPassword(uid_t user, const std::string &newPassword) const {
         return try_catch([&] {
             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);
@@ -146,32 +176,11 @@ public:
     }
 
     virtual ~ControlImpl(){}
-};
-
-Control::Control()
-  : m_impl(new ControlImpl)
-{}
-
-Control::~Control(){}
-
-int Control::unlockUserKey(uid_t user, const std::string &password) const {
-    return m_impl->unlockUserKey(user, password);
-}
 
-int Control::lockUserKey(uid_t user) const {
-    return m_impl->lockUserKey(user);
-}
-
-int Control::removeUserData(uid_t user) const {
-    return m_impl->removeUserData(user);
-}
-
-int Control::changeUserPassword(uid_t user, const std::string &oldPassword, const std::string &newPassword) const {
-    return m_impl->changeUserPassword(user, oldPassword, newPassword);
-}
+};
 
-int Control::resetUserPassword(uid_t user, const std::string &newPassword) const {
-    return m_impl->resetUserPassword(user, newPassword);
+ControlShPtr Control::create() {
+    return ControlShPtr(new ControlImpl());
 }
 
 } // namespace CKM