Refactor error handling 14/159914/17
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 10 Nov 2017 16:01:46 +0000 (17:01 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 24 Nov 2017 09:51:20 +0000 (10:51 +0100)
- Move error translation to a separate file
- Use common error codes in all API
- Convert internal error enum to integers (klay does not support enum
  serialization at the moment)
- Update documentation

Change-Id: I0bc49c2a4218e0f4e833bd404dfec50164ad1d1f

22 files changed:
lib/CMakeLists.txt
lib/external-encryption.cpp
lib/internal-encryption.cpp
lib/luks.cpp
lib/ode/common.h
lib/ode/error-translation.cpp [new file with mode: 0644]
lib/ode/error-translation.h [new file with mode: 0644]
lib/ode/external-encryption.cpp
lib/ode/external-encryption.h
lib/ode/internal-encryption.cpp
lib/ode/internal-encryption.h
lib/ode/keys.h
lib/ode/luks.cpp
lib/ode/luks.h
lib/ode/secure-erase.cpp
lib/ode/secure-erase.h
lib/secure-erase.cpp
rmi/common.h
server/external-encryption.cpp
server/internal-encryption.cpp
server/luks.cpp
server/secure-erase.cpp

index 64859ae..6f4a10c 100755 (executable)
@@ -27,6 +27,7 @@ SET(SOURCES client.cpp
                        ode/internal-encryption.cpp
                        ode/external-encryption.cpp
                        ode/luks.cpp
+                       ode/error-translation.cpp
 )
 
 SET(CAPI_INCLUDE_FILES  ode/common.h
index 9870b8c..6f9eae2 100644 (file)
@@ -14,6 +14,7 @@
  *  limitations under the License
  */
 #include "external-encryption.h"
+#include "rmi/common.h"
 
 namespace ode {
 
@@ -31,7 +32,7 @@ int ExternalEncryptionClient::setMountPassword(const std::string& password)
        try {
                return context->methodCall<int>("ExternalEncryptionServer::setMountPassword", password);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -40,7 +41,7 @@ int ExternalEncryptionClient::mount()
        try {
                return context->methodCall<int>("ExternalEncryptionServer::mount");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -49,7 +50,7 @@ int ExternalEncryptionClient::umount()
        try {
                return context->methodCall<int>("ExternalEncryptionServer::umount");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -58,7 +59,7 @@ int ExternalEncryptionClient::encrypt(const std::string& password, unsigned int
        try {
                return context->methodCall<int>("ExternalEncryptionServer::encrypt", password, options);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -67,7 +68,7 @@ int ExternalEncryptionClient::decrypt(const std::string& password)
        try {
                return context->methodCall<int>("ExternalEncryptionServer::decrypt", password);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -76,7 +77,7 @@ int ExternalEncryptionClient::recovery()
        try {
                return context->methodCall<int>("ExternalEncryptionServer::recovery");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -85,7 +86,7 @@ int ExternalEncryptionClient::isPasswordInitialized()
        try {
                return context->methodCall<int>("ExternalEncryptionServer::isPasswordInitialized");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -95,7 +96,7 @@ int ExternalEncryptionClient::initPassword(const std::string& password)
                return context->methodCall<int>("ExternalEncryptionServer::initPassword",
                                                                                password);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -105,7 +106,7 @@ int ExternalEncryptionClient::cleanPassword(const std::string& password)
                return context->methodCall<int>("ExternalEncryptionServer::cleanPassword",
                                                                                password);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -116,7 +117,7 @@ int ExternalEncryptionClient::changePassword(const std::string& oldPassword,
                return context->methodCall<int>("ExternalEncryptionServer::changePassword",
                                                                                oldPassword, newPassword);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -126,7 +127,7 @@ int ExternalEncryptionClient::verifyPassword(const std::string& password)
                return context->methodCall<int>("ExternalEncryptionServer::verifyPassword",
                                                                                password);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -135,7 +136,7 @@ int ExternalEncryptionClient::getState()
        try {
                return context->methodCall<int>("ExternalEncryptionServer::getState");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -144,7 +145,7 @@ unsigned int ExternalEncryptionClient::getSupportedOptions()
        try {
                return context->methodCall<unsigned int>("ExternalEncryptionServer::getSupportedOptions");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
index 614e023..7c0feb7 100644 (file)
@@ -14,6 +14,7 @@
  *  limitations under the License
  */
 #include "internal-encryption.h"
+#include "rmi/common.h"
 
 namespace ode {
 
@@ -31,7 +32,7 @@ int InternalEncryptionClient::setMountPassword(const std::string& password)
        try {
                return context->methodCall<int>("InternalEncryptionServer::setMountPassword", password);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -40,7 +41,7 @@ int InternalEncryptionClient::mount()
        try {
                return context->methodCall<int>("InternalEncryptionServer::mount");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -49,7 +50,7 @@ int InternalEncryptionClient::umount()
        try {
                return context->methodCall<int>("InternalEncryptionServer::umount");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -58,7 +59,7 @@ int InternalEncryptionClient::encrypt(const std::string& password, unsigned int
        try {
                return context->methodCall<int>("InternalEncryptionServer::encrypt", password, options);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -67,7 +68,7 @@ int InternalEncryptionClient::decrypt(const std::string& password)
        try {
                return context->methodCall<int>("InternalEncryptionServer::decrypt", password);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -76,7 +77,7 @@ int InternalEncryptionClient::recovery()
        try {
                return context->methodCall<int>("InternalEncryptionServer::recovery");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -85,7 +86,7 @@ int InternalEncryptionClient::isPasswordInitialized()
        try {
                return context->methodCall<int>("InternalEncryptionServer::isPasswordInitialized");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -95,7 +96,7 @@ int InternalEncryptionClient::initPassword(const std::string& password)
                return context->methodCall<int>("InternalEncryptionServer::initPassword",
                                                                                password);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -105,7 +106,7 @@ int InternalEncryptionClient::cleanPassword(const std::string& password)
                return context->methodCall<int>("InternalEncryptionServer::cleanPassword",
                                                                                password);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -116,7 +117,7 @@ int InternalEncryptionClient::changePassword(const std::string& oldPassword,
                return context->methodCall<int>("InternalEncryptionServer::changePassword",
                                                                                oldPassword, newPassword);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -126,7 +127,7 @@ int InternalEncryptionClient::verifyPassword(const std::string& password)
                return context->methodCall<int>("InternalEncryptionServer::verifyPassword",
                                                                                password);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -135,7 +136,7 @@ int InternalEncryptionClient::getState()
        try {
                return context->methodCall<int>("InternalEncryptionServer::getState");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -144,7 +145,7 @@ unsigned int InternalEncryptionClient::getSupportedOptions()
        try {
                return context->methodCall<unsigned int>("InternalEncryptionServer::getSupportedOptions");
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
index 766a32b..1fb236d 100644 (file)
@@ -14,6 +14,7 @@
  *  limitations under the License
  */
 #include "luks.h"
+#include "rmi/common.h"
 
 namespace ode {
 
@@ -36,7 +37,7 @@ int LuksClient::format(bool sync,
                                                                                device,
                                                                                password);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -52,7 +53,7 @@ int LuksClient::open(bool sync,
                                                                                password,
                                                                                mapping);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
@@ -61,7 +62,7 @@ int LuksClient::close(bool sync, const std::string& mapping)
        try {
                return context->methodCall<int>("LuksServer::close", sync, mapping);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
index 86ac626..275356f 100644 (file)
@@ -53,14 +53,11 @@ typedef enum {
        ODE_ERROR_NONE                 = TIZEN_ERROR_NONE,                 /**< The operation was successful */
        ODE_ERROR_INVALID_PARAMETER    = TIZEN_ERROR_INVALID_PARAMETER,    /**< Invalid parameter */
        ODE_ERROR_CONNECTION_REFUSED   = TIZEN_ERROR_CONNECTION_REFUSED,   /**< Connection refused */
-       ODE_ERROR_TIMED_OUT            = TIZEN_ERROR_TIMED_OUT,            /**< Time out */
        ODE_ERROR_PERMISSION_DENIED    = TIZEN_ERROR_PERMISSION_DENIED,    /**< Access privilege is not sufficient */
-       ODE_ERROR_NOT_SUPPORTED        = TIZEN_ERROR_NOT_SUPPORTED,        /**< Operation is not supported */
        ODE_ERROR_NO_SUCH_FILE         = TIZEN_ERROR_NO_SUCH_FILE,         /**< No such file or directory */
-       ODE_ERROR_FILE_EXISTS          = TIZEN_ERROR_FILE_EXISTS,          /**< File exists */
        ODE_ERROR_OUT_OF_MEMORY        = TIZEN_ERROR_OUT_OF_MEMORY,        /**< Out of memory */
-       ODE_ERROR_NOT_PERMITTED        = TIZEN_ERROR_NOT_PERMITTED,        /**< Operation is not permitted */
-       ODE_ERROR_KEY_REJECTED         = TIZEN_ERROR_KEY_REJECTED,         /**< Passwor is rejected */
+       ODE_ERROR_NO_SUCH_DEVICE       = TIZEN_ERROR_NO_SUCH_DEVICE,       /**< No such device */
+       ODE_ERROR_KEY_REJECTED         = TIZEN_ERROR_KEY_REJECTED,         /**< Password is rejected */
        ODE_ERROR_NO_DATA              = TIZEN_ERROR_NO_DATA,              /**< No Data */
        ODE_ERROR_RESOURCE_BUSY        = TIZEN_ERROR_RESOURCE_BUSY,        /**< Device or resource busy */
        ODE_ERROR_UNKNOWN              = TIZEN_ERROR_UNKNOWN               /**< Unknown error */
diff --git a/lib/ode/error-translation.cpp b/lib/ode/error-translation.cpp
new file mode 100644 (file)
index 0000000..722fab3
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include "error-translation.h"
+#include "common.h"
+#include "rmi/common.h"
+
+#include <map>
+
+using namespace ode;
+
+namespace {
+
+std::map<int, int> ODE_ERROR_TO_API_ERROR = {
+       { error::None, ODE_ERROR_NONE },
+       { error::InvalidParameter, ODE_ERROR_INVALID_PARAMETER },
+       { error::ConnectionRefused, ODE_ERROR_CONNECTION_REFUSED },
+       { error::PermissionDenied, ODE_ERROR_PERMISSION_DENIED },
+       { error::NoSuchFile, ODE_ERROR_NO_SUCH_FILE },
+       { error::OutOfMemory, ODE_ERROR_OUT_OF_MEMORY },
+       { error::NoSuchDevice, ODE_ERROR_NO_SUCH_DEVICE },
+       { error::WrongPassword, ODE_ERROR_KEY_REJECTED },
+       { error::NoData, ODE_ERROR_NO_DATA },
+       { error::DeviceBusy, ODE_ERROR_RESOURCE_BUSY },
+       { error::Unknown, ODE_ERROR_UNKNOWN }
+};
+} // anonymous namespace
+
+int toApiError(int error)
+{
+       int ret = ODE_ERROR_UNKNOWN;
+       auto it = ODE_ERROR_TO_API_ERROR.find(error);
+       if (it != ODE_ERROR_TO_API_ERROR.end())
+               ret = it->second;
+       return ret;
+}
diff --git a/lib/ode/error-translation.h b/lib/ode/error-translation.h
new file mode 100644 (file)
index 0000000..fcae724
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#ifndef __CAPI_ODE_ERROR_TRANSLATION_H__
+#define __CAPI_ODE_ERROR_TRANSLATION_H__
+
+int toApiError(int error);
+
+#endif // __CAPI_ODE_ERROR_TRANSLATION_H__
index f10b7e8..c417528 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "client.h"
 #include "lib/external-encryption.h"
+#include "error-translation.h"
+#include "rmi/common.h"
 
 using namespace ode;
 
@@ -30,7 +32,7 @@ int ode_external_encryption_set_mount_password(const char* password)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
-       return external.setMountPassword(password);
+       return toApiError(external.setMountPassword(password));
 }
 
 int ode_external_encryption_mount()
@@ -39,7 +41,7 @@ int ode_external_encryption_mount()
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
-       return external.mount();
+       return toApiError(external.mount());
 }
 
 int ode_external_encryption_umount()
@@ -48,7 +50,7 @@ int ode_external_encryption_umount()
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
-       return external.umount();
+       return toApiError(external.umount());
 }
 
 int ode_external_encryption_encrypt(const char* password, unsigned int options)
@@ -59,7 +61,7 @@ int ode_external_encryption_encrypt(const char* password, unsigned int options)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
-       return external.encrypt(password, options);
+       return toApiError(external.encrypt(password, options));
 }
 
 int ode_external_encryption_decrypt(const char* password)
@@ -70,7 +72,7 @@ int ode_external_encryption_decrypt(const char* password)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
-       return external.decrypt(password);
+       return toApiError(external.decrypt(password));
 }
 
 int ode_external_encryption_recovery()
@@ -79,7 +81,7 @@ int ode_external_encryption_recovery()
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
-       return external.recovery();
+       return toApiError(external.recovery());
 }
 
 int ode_external_encryption_is_password_initialized(bool* result)
@@ -91,9 +93,13 @@ int ode_external_encryption_is_password_initialized(bool* result)
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
        int ret = external.isPasswordInitialized();
 
-       RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+       if (ret == error::None)
+               *result = true;
+       else if (ret == error::NoSuchFile)
+               *result = false;
+       else
+               return toApiError(ret);
 
-       *result = ret;
        return ODE_ERROR_NONE;
 }
 
@@ -105,7 +111,7 @@ int ode_external_encryption_init_password(const char* password)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
-       return external.initPassword(password);
+       return toApiError(external.initPassword(password));
 }
 
 int ode_external_encryption_clean_password(const char* password)
@@ -116,7 +122,7 @@ int ode_external_encryption_clean_password(const char* password)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
-       return external.cleanPassword(password);
+       return toApiError(external.cleanPassword(password));
 }
 
 int ode_external_encryption_change_password(const char* old_password,
@@ -129,7 +135,7 @@ int ode_external_encryption_change_password(const char* old_password,
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
-       return external.changePassword(old_password, new_password);
+       return toApiError(external.changePassword(old_password, new_password));
 }
 
 int ode_external_encryption_verify_password(const char* password, bool* result)
@@ -142,9 +148,13 @@ int ode_external_encryption_verify_password(const char* password, bool* result)
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
        int ret = external.verifyPassword(password);
 
-       RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+       if (ret == error::None)
+               *result = true;
+       else if (ret == error::WrongPassword)
+               *result = false;
+       else
+               return toApiError(ret);
 
-       *result = ret;
        return ODE_ERROR_NONE;
 }
 
@@ -157,7 +167,8 @@ int ode_external_encryption_get_state(int* state)
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
        int ret = external.getState();
 
-       RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+       if (ret < 0)
+               return toApiError(ret);
 
        *state = ret;
        return ODE_ERROR_NONE;
@@ -184,9 +195,7 @@ int ode_external_encryption_set_mount_event_cb(ode_mount_event_cb callback, void
        RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
 
        int ret = mountEventCallbackContext->subscribeSignal("ExternalEncryption::mount", callback, user_data);
-       RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
-
-       return ODE_ERROR_NONE;
+       return toApiError(ret);
 }
 
 int ode_external_encryption_unset_mount_event_cb()
index a64f561..3556bab 100644 (file)
@@ -38,10 +38,11 @@ extern "C" {
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_KEY_REJECTED Password doen't match
+ * @retval      #ODE_ERROR_KEY_REJECTED Password doesn't match
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         The password must match with what is set by
  *              ode_external_encryption_init_password().
  * @see         ode_external_encryption_init_password()
@@ -56,12 +57,12 @@ ODE_API int ode_external_encryption_set_mount_password(const char* password);
  * @since_tizen 4.0
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
- * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
+ * @retval      #ODE_ERROR_NO_SUCH_DEVICE External storage is not encrypted
  * @retval      #ODE_ERROR_NO_DATA Password isn't set
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         A password must be set by
  *              ode_external_encryption_set_mount_password() before every
  *              mount attempt.
@@ -76,11 +77,11 @@ ODE_API int ode_external_encryption_mount();
  * @since_tizen 4.0
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
- * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_NO_SUCH_DEVICE External storage is not encrypted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_external_encryption_mount()
  */
 ODE_API int ode_external_encryption_umount();
@@ -94,12 +95,12 @@ ODE_API int ode_external_encryption_umount();
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_KEY_REJECTED Password doen't match
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_KEY_REJECTED Password doesn't match
+ * @retval      #ODE_ERROR_NO_SUCH_DEVICE External storage is not decrypted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
- * @retval      #ODE_ERROR_NOT_SUPPORTED Given options are not supported
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_external_encryption_mount()
  * @see         ode_external_encryption_decrypt()
  * @see         ode_external_encryption_get_supported_options()
@@ -114,11 +115,12 @@ ODE_API int ode_external_encryption_encrypt(const char* password, unsigned int o
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_KEY_REJECTED Password doen't match
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_KEY_REJECTED Password doesn't match
+ * @retval      #ODE_ERROR_NO_SUCH_DEVICE External storage is not encrypted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         The password must match with what is set by
  *              ode_external_encryption_init_password().
  * @see         ode_external_encryption_encrypt()
@@ -134,11 +136,11 @@ ODE_API int ode_external_encryption_decrypt(const char* password);
  * @since_tizen 4.0
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
- * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_NO_SUCH_DEVICE External storage is decrypted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_external_encryption_encrypt()
  */
 ODE_API int ode_external_encryption_recovery();
@@ -153,10 +155,8 @@ ODE_API int ode_external_encryption_recovery();
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
- * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
- *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_external_encryption_init_password()
  * @see         ode_external_encryption_clean_password()
  */
@@ -171,10 +171,10 @@ ODE_API int ode_external_encryption_is_password_initialized(bool* result);
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_external_encryption_change_password()
  * @see         ode_external_encryption_clean_password()
  * @see         ode_external_encryption_encrypt()
@@ -192,11 +192,11 @@ ODE_API int ode_external_encryption_init_password(const char* password);
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_KEY_REJECTED old_password doen't match
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_KEY_REJECTED Password doesn't match
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         The password must match with what is set by
  *              ode_external_encryption_init_password().
  * @see         ode_external_encryption_init_password()
@@ -213,11 +213,11 @@ ODE_API int ode_external_encryption_clean_password(const char* password);
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_KEY_REJECTED old_password doen't match
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_KEY_REJECTED Old password doesn't match
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         The password must match with what is set by
  *              ode_external_encryption_init_password().
  * @see         ode_external_encryption_encrypt()
@@ -235,9 +235,10 @@ ODE_API int ode_external_encryption_change_password(const char* old_password,
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         The password must match with what is set by
  *              ode_external_encryption_init_password().
  * @see         ode_external_encryption_encrypt()
@@ -253,9 +254,8 @@ ODE_API int ode_external_encryption_verify_password(const char* password, bool*
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
- *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_external_encryption_encrypt()
  * @see         ode_external_encryption_decrypt()
  */
@@ -279,9 +279,8 @@ typedef enum {
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
- *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_external_encryption_encrypt()
  */
 ODE_API int ode_external_encryption_get_supported_options(unsigned int* options);
@@ -296,7 +295,8 @@ ODE_API int ode_external_encryption_get_supported_options(unsigned int* options)
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @post        If the callback is not needed,
  *              ode_external_encryption_unset_mount_event_cb() must be called.
  * @see         ode_external_encryption_mount()
@@ -311,8 +311,6 @@ ODE_API int ode_external_encryption_set_mount_event_cb(ode_mount_event_cb callba
  * @since_tizen 4.0
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- *              the privilege to call this API
  * @see         ode_external_encryption_mount()
  * @see         ode_external_encryption_set_mount_event_cb()
  */
index 8364cbf..a5f1cfe 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "client.h"
 #include "lib/internal-encryption.h"
+#include "error-translation.h"
+#include "rmi/common.h"
 
 using namespace ode;
 
@@ -30,7 +32,7 @@ int ode_internal_encryption_set_mount_password(const char* password)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
-       return internal.setMountPassword(password);
+       return toApiError(internal.setMountPassword(password));
 }
 
 int ode_internal_encryption_mount()
@@ -39,7 +41,7 @@ int ode_internal_encryption_mount()
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
-       return internal.mount();
+       return toApiError(internal.mount());
 }
 
 int ode_internal_encryption_umount()
@@ -48,7 +50,7 @@ int ode_internal_encryption_umount()
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
-       return internal.umount();
+       return toApiError(internal.umount());
 }
 
 int ode_internal_encryption_encrypt(const char* password, unsigned int options)
@@ -59,7 +61,7 @@ int ode_internal_encryption_encrypt(const char* password, unsigned int options)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
-       return internal.encrypt(password, options);
+       return toApiError(internal.encrypt(password, options));
 }
 
 int ode_internal_encryption_decrypt(const char* password)
@@ -70,7 +72,7 @@ int ode_internal_encryption_decrypt(const char* password)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
-       return internal.decrypt(password);
+       return toApiError(internal.decrypt(password));
 }
 
 int ode_internal_encryption_recovery()
@@ -79,44 +81,48 @@ int ode_internal_encryption_recovery()
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
-       return internal.recovery();
+       return toApiError(internal.recovery());
 }
 
 int ode_internal_encryption_is_password_initialized(bool* result)
 {
-    RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
 
-    ClientContext client;
-    RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       ClientContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
        int ret = internal.isPasswordInitialized();
 
-       RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+       if (ret == error::None)
+               *result = true;
+       else if (ret == error::NoSuchFile)
+               *result = false;
+       else
+               return toApiError(ret);
 
-       *result = ret;
-    return ODE_ERROR_NONE;
+       return ODE_ERROR_NONE;
 }
 
 int ode_internal_encryption_init_password(const char* password)
 {
-    RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-    ClientContext client;
-    RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       ClientContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
-       return internal.initPassword(password);
+       return toApiError(internal.initPassword(password));
 }
 
 int ode_internal_encryption_clean_password(const char* password)
 {
-    RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-    ClientContext client;
-    RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       ClientContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
-       return internal.cleanPassword(password);
+       return toApiError(internal.cleanPassword(password));
 }
 
 int ode_internal_encryption_change_password(const char* old_password,
@@ -129,23 +135,27 @@ int ode_internal_encryption_change_password(const char* old_password,
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
-       return internal.changePassword(old_password, new_password);
+       return toApiError(internal.changePassword(old_password, new_password));
 }
 
 int ode_internal_encryption_verify_password(const char* password, bool* result)
 {
-    RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
-    RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
 
-    ClientContext client;
-    RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       ClientContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
        int ret = internal.verifyPassword(password);
 
-       RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+       if (ret == error::None)
+               *result = true;
+       else if (ret == error::WrongPassword)
+               *result = false;
+       else
+               return toApiError(ret);
 
-       *result = ret;
-    return ODE_ERROR_NONE;
+       return ODE_ERROR_NONE;
 }
 
 int ode_internal_encryption_get_state(int* state)
@@ -157,7 +167,8 @@ int ode_internal_encryption_get_state(int* state)
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
        int ret = internal.getState();
 
-       RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+       if (ret < 0)
+               return toApiError(ret);
 
        *state = ret;
        return ODE_ERROR_NONE;
@@ -183,10 +194,8 @@ int ode_internal_encryption_set_mount_event_cb(ode_mount_event_cb callback, void
        mountEventCallbackContext.reset(new ClientContext);
        RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
 
-    int ret = mountEventCallbackContext->subscribeSignal("InternalEncryptionServer::mount", callback, user_data);
-       RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
-
-       return ODE_ERROR_NONE;
+       int ret = mountEventCallbackContext->subscribeSignal("InternalEncryptionServer::mount", callback, user_data);
+       return toApiError(ret);
 }
 
 int ode_internal_encryption_unset_mount_event_cb()
index bd98adf..6ef916e 100644 (file)
@@ -37,10 +37,11 @@ extern "C" {
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_KEY_REJECTED Password doen't match
+ * @retval      #ODE_ERROR_KEY_REJECTED Password doesn't match
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         The password set before must match with what is set by
  *              ode_internal_encryption_init_password().
  * @see         ode_internal_encryption_init_password()
@@ -55,12 +56,12 @@ ODE_API int ode_internal_encryption_set_mount_password(const char* password);
  * @since_tizen 4.0
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
- * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
+ * @retval      #ODE_ERROR_NO_SUCH_DEVICE Internal storage is not encrypted
  * @retval      #ODE_ERROR_NO_DATA Password isn't set
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         A password must be set by
  *              ode_internal_encryption_set_mount_password() before every
  *              mount attempt.
@@ -75,11 +76,11 @@ ODE_API int ode_internal_encryption_mount();
  * @since_tizen 4.0
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
- * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_NO_SUCH_DEVICE Internal storage is not encrypted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_internal_encryption_mount()
  */
 ODE_API int ode_internal_encryption_umount();
@@ -93,12 +94,12 @@ ODE_API int ode_internal_encryption_umount();
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_KEY_REJECTED Password doen't match
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_KEY_REJECTED Password doesn't match
+ * @retval      #ODE_ERROR_NO_SUCH_DEVICE Internal storage is not decrypted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
- * @retval      #ODE_ERROR_NOT_SUPPORTED Given options are not supported
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         The password must match with what is set by
  *              ode_internal_encryption_init_password().
  * @see         ode_internal_encryption_mount()
@@ -115,11 +116,12 @@ ODE_API int ode_internal_encryption_encrypt(const char* password, unsigned int o
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_KEY_REJECTED Password doen't match
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_KEY_REJECTED Password doesn't match
+ * @retval      #ODE_ERROR_NO_SUCH_DEVICE Internal storage is not encrypted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         The password must match with what is set by
  *              ode_internal_encryption_init_password().
  * @see         ode_internal_encryption_encrypt()
@@ -135,11 +137,11 @@ ODE_API int ode_internal_encryption_decrypt(const char* password);
  * @since_tizen 4.0
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
- * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_NO_SUCH_DEVICE Internal storage is decrypted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_internal_encryption_encrypt()
  */
 ODE_API int ode_internal_encryption_recovery();
@@ -154,10 +156,8 @@ ODE_API int ode_internal_encryption_recovery();
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
- * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
- *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_internal_encryption_init_password()
  * @see         ode_internal_encryption_clean_password()
  */
@@ -172,10 +172,10 @@ ODE_API int ode_internal_encryption_is_password_initialized(bool* result);
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_internal_encryption_change_password()
  * @see         ode_internal_encryption_clean_password()
  * @see         ode_internal_encryption_encrypt()
@@ -193,11 +193,11 @@ ODE_API int ode_internal_encryption_init_password(const char* password);
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_KEY_REJECTED old_password doen't match
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_KEY_REJECTED Password doesn't match
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         The password must match with what is set by
  *              ode_internal_encryption_init_password().
  * @see         ode_internal_encryption_init_password()
@@ -214,11 +214,11 @@ ODE_API int ode_internal_encryption_clean_password(const char* password);
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_KEY_REJECTED old_password doen't match
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_KEY_REJECTED Old password doesn't match
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         Old password must match with what is set by
  *              ode_internal_encryption_init_password().
  * @see         ode_internal_encryption_init_password()
@@ -236,9 +236,10 @@ ODE_API int ode_internal_encryption_change_password(const char* old_password,
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         The password must match with what is set by
  *              ode_internal_encryption_init_password().
  * @see         ode_internal_encryption_init_password()
@@ -255,9 +256,8 @@ ODE_API int ode_internal_encryption_verify_password(const char* password, bool*
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
- *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_internal_encryption_encrypt()
  * @see         ode_internal_encryption_decrypt()
  */
@@ -280,9 +280,8 @@ typedef enum {
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
- *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @see         ode_internal_encryption_encrypt()
  */
 ODE_API int ode_internal_encryption_get_supported_options(unsigned int* options);
@@ -297,7 +296,8 @@ ODE_API int ode_internal_encryption_get_supported_options(unsigned int* options)
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @post        If the callback is not needed,
  *              ode_internal_encryption_unset_mount_event_cb() must be called.
  * @see         ode_internal_encryption_mount()
@@ -312,8 +312,6 @@ ODE_API int ode_internal_encryption_set_mount_event_cb(ode_mount_event_cb callba
  * @since_tizen 4.0
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
- * @retval      #ODE_ERROR_TIMED_OUT Time out
- *              the privilege to call this API
  * @see         ode_internal_encryption_set_mount_event_cb()
  */
 ODE_API int ode_internal_encryption_unset_mount_event_cb();
index 500fd51..d085799 100644 (file)
@@ -55,6 +55,7 @@ typedef enum {
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  *
  * @see         ode_key_init()
  * @see         ode_key_clean()
@@ -77,7 +78,10 @@ ODE_API int ode_key_is_initialized(const char* device, bool* result);
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
  * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  *
  * @see         ode_key_change_password()
  * @see         ode_key_clean()
@@ -103,7 +107,12 @@ ODE_API int ode_key_init(const char* device,
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #ODE_ERROR_KEY_REJECTED Password doesn't match
+ * @retval      #ODE_ERROR_NO_SUCH_FILE No key exists for given @a device
+ * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
  * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  *
  * @pre         The @a password must match the current password used for
  *              @a device key encryption
@@ -128,7 +137,12 @@ ODE_API int ode_key_remove(const char* device, const char* password);
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #ODE_ERROR_KEY_REJECTED Current password doesn't match
+ * @retval      #ODE_ERROR_NO_SUCH_FILE No key exists for given @a device
+ * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
  * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  *
  * @pre         The @a cur_password must match the current password used for
  *              @a device key encryption
@@ -156,7 +170,11 @@ ODE_API int ode_key_change_password(const char* device,
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #ODE_ERROR_NO_SUCH_FILE No key exists for given @a device
+ * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
  * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  *
  * @see         ode_key_init()
  * @see         ode_key_change_password()
index 11390f6..2b53dfb 100644 (file)
 #include "client.h"
 #include "lib/luks.h"
 #include "rmi/common.h"
+#include "error-translation.h"
 
 using namespace ode;
 
 namespace {
 std::unique_ptr<ClientContext> luksEventCallbackContext;
 
-// TODO Extend it and make it common for whole API
-std::map<OdeError, int> ODE_ERROR_TO_API_ERROR = {
-               { OdeError::None, ODE_ERROR_NONE },
-               { OdeError::InvalidParameter, ODE_ERROR_INVALID_PARAMETER },
-               { OdeError::WrongPassword, ODE_ERROR_KEY_REJECTED },
-               { OdeError::OutOfMemory, ODE_ERROR_OUT_OF_MEMORY },
-               { OdeError::NoSuchFile, ODE_ERROR_NO_SUCH_FILE },
-               { OdeError::DeviceBusy, ODE_ERROR_RESOURCE_BUSY },
-               { OdeError::Unknown, ODE_ERROR_UNKNOWN }
-};
-
-int toApiError(int error)
-{
-       int ret = ODE_ERROR_UNKNOWN;
-       auto it = ODE_ERROR_TO_API_ERROR.find(static_cast<OdeError>(error));
-       if (it != ODE_ERROR_TO_API_ERROR.end())
-               ret = it->second;
-       return ret;
-}
-
 int luks_format_internal(bool sync, const char* device, const char* password)
 {
        RET_ON_FAILURE(device, ODE_ERROR_INVALID_PARAMETER);
@@ -56,7 +37,7 @@ int luks_format_internal(bool sync, const char* device, const char* password)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        LuksClient luks = client.createInterface<LuksClient>();
 
-       return luks.format(sync, device, password);
+       return toApiError(luks.format(sync, device, password));
 }
 
 int luks_open_internal(bool sync,
@@ -72,7 +53,7 @@ int luks_open_internal(bool sync,
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        LuksClient luks = client.createInterface<LuksClient>();
 
-       return luks.open(sync, device, password, mapping);
+       return toApiError(luks.open(sync, device, password, mapping));
 }
 
 int luks_close_internal(bool sync, const char* mapping)
@@ -83,7 +64,7 @@ int luks_close_internal(bool sync, const char* mapping)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        LuksClient luks = client.createInterface<LuksClient>();
 
-       return luks.close(sync, mapping);
+       return toApiError(luks.close(sync, mapping));
 }
 
 } // anonymous namespace
@@ -117,9 +98,7 @@ int ode_luks_set_event_cb(ode_luks_event_cb callback, void *user_data)
        };
 
        ret = luksEventCallbackContext->subscribeSignal(Luks::NOTIFICATION, cb);
-       RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
-
-       return ODE_ERROR_NONE;
+       return toApiError(ret);
 }
 
 void ode_luks_unset_event_cb()
@@ -129,18 +108,15 @@ void ode_luks_unset_event_cb()
 
 int ode_luks_format_sync(const char* device, const char* password)
 {
-       int err = luks_format_internal(true, device, password);
-       return toApiError(err);
+       return luks_format_internal(true, device, password);
 }
 
 int ode_luks_open_sync(const char* device, const char* password, const char* mapping)
 {
-       int err = luks_open_internal(true, device, password, mapping);
-       return toApiError(err);
+       return  luks_open_internal(true, device, password, mapping);
 }
 
 int ode_luks_close_sync(const char* mapping)
 {
-       int err = luks_close_internal(true, mapping);
-       return toApiError(err);
+       return luks_close_internal(true, mapping);
 }
index d7e6073..fa7f112 100644 (file)
@@ -125,7 +125,7 @@ ODE_API int ode_luks_format(const char* device, const char* password);
  *              function as a result of this function call:
  *              #ODE_ERROR_NONE Successful
  *              #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- *              #ODE_ERROR_KEY_REJECTED Wrong password
+ *              #ODE_ERROR_KEY_REJECTED Password doesn't match
  *              #ODE_ERROR_OUT_OF_MEMORY Out of memory
  *              #ODE_ERROR_NO_SUCH_FILE Wrong device or mapping
  *              #ODE_ERROR_RESOURCE_BUSY Device is busy
@@ -264,7 +264,7 @@ ODE_API int ode_luks_format_sync(const char* device, const char* password);
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
- * @retval      #ODE_ERROR_KEY_REJECTED Wrong password
+ * @retval      #ODE_ERROR_KEY_REJECTED Password doesn't match
  * @retval      #ODE_ERROR_OUT_OF_MEMORY Out of memory
  * @retval      #ODE_ERROR_NO_SUCH_FILE Wrong device or mapping
  * @retval      #ODE_ERROR_RESOURCE_BUSY Device is busy
index 64d97f8..db08d47 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "client.h"
 #include "lib/secure-erase.h"
+#include "error-translation.h"
 
 using namespace ode;
 
@@ -30,5 +31,5 @@ int ode_secure_clean(const char* name)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        SecureEraseClient secure = client.createInterface<SecureEraseClient>();
 
-       return secure.clean(name);
+       return toApiError(secure.clean(name));
 }
index e70ee1d..9b4714b 100644 (file)
@@ -36,11 +36,11 @@ extern "C" {
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval      #ODE_ERROR_TIMED_OUT Time out
  * @retval      #ODE_ERROR_NO_SUCH_FILE No such file or directory
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
  * @pre         The device to the given name must be exists.
  */
 ODE_API int ode_secure_clean(const char* name);
index f582efa..9ee1759 100644 (file)
@@ -14,6 +14,7 @@
  *  limitations under the License
  */
 #include "secure-erase.h"
+#include "rmi/common.h"
 
 namespace ode {
 
@@ -31,7 +32,7 @@ int SecureEraseClient::clean(const std::string& name)
        try {
                return context->methodCall<int>("SecureEraseServer::clean", name);
        } catch (runtime::Exception& e) {
-               return -1;
+               return error::Unknown;
        }
 }
 
index 43336b0..4a634b6 100644 (file)
 
 namespace ode {
 
-enum class OdeError {
-       None = 0,
-       InvalidParameter,
-       WrongPassword,
-       OutOfMemory,
-       NoSuchFile,
-       DeviceBusy,
-       Unknown
+// TODO make it an enum when klay starts to support enum serialization in rmi
+namespace error {
+
+const int None = 0;
+const int InvalidParameter = -1;
+const int ConnectionRefused = -2;
+const int PermissionDenied = -3;
+const int NoSuchFile = -4;
+const int OutOfMemory = -5;
+const int NoSuchDevice = -6;
+const int WrongPassword = -7;
+const int NoData = -8;
+const int DeviceBusy = -9;
+const int Unknown = -10;
+
 };
 
 } // namespace ode
index 0955fbe..5b0452d 100644 (file)
@@ -31,6 +31,7 @@
 #include "launchpad.h"
 #include "app-bundle.h"
 #include "progress-bar.h"
+#include "rmi/common.h"
 
 #include "external-encryption.h"
 
@@ -219,19 +220,19 @@ int ExternalEncryptionServer::setMountPassword(const std::string& password)
        KeyManager keyManager(engine->getKeyMeta());
        if (!keyManager.verifyPassword(pwData)) {
                ERROR(SINK, "Wrong password passed.");
-               return -2;
+               return error::WrongPassword;
        }
 
        mountKey = keyManager.getMasterKey(pwData);
 
-       return 0;
+       return error::None;
 }
 
 int ExternalEncryptionServer::mount()
 {
        if (mountKey.empty()) {
                ERROR(SINK, "You need to call set_mount_password() first.");
-               return -1;
+               return error::NoData;
        }
 
        KeyManager::data key = mountKey;
@@ -239,12 +240,12 @@ int ExternalEncryptionServer::mount()
 
        if (getState() != State::Encrypted) {
                ERROR(SINK, "Cannot mount, SD card's state incorrect.");
-               return -1;
+               return error::NoSuchDevice;
        }
 
        if (engine->isMounted()) {
                INFO(SINK, "SD card already mounted.");
-               return 0;
+               return error::None;
        }
 
        INFO(SINK, "Mounting external storage.");
@@ -252,24 +253,24 @@ int ExternalEncryptionServer::mount()
                engine->mount(key, getOptions());
        } catch (runtime::Exception &e) {
                ERROR(SINK, "Failed to mount: " + std::string(e.what()));
-               return -3;
+               return error::Unknown;
        }
 
        server.notify("ExternalEncryptionServer::mount");
 
-       return 0;
+       return error::None;
 }
 
 int ExternalEncryptionServer::umount()
 {
        if (getState() != State::Encrypted) {
                ERROR(SINK, "Cannot umount, SD card's state incorrect.");
-               return -1;
+               return error::NoSuchDevice;
        }
 
        if (!engine->isMounted()) {
                INFO(SINK, "SD card already umounted.");
-               return 0;
+               return error::None;
        }
 
        INFO(SINK, "Closing all applications using external storage.");
@@ -280,17 +281,17 @@ int ExternalEncryptionServer::umount()
                engine->umount();
        } catch (runtime::Exception &e) {
                ERROR(SINK, "Failed to umount: " + std::string(e.what()));
-               return -3;
+               return error::Unknown;
        }
 
-       return 0;
+       return error::None;
 }
 
 int ExternalEncryptionServer::encrypt(const std::string &password, unsigned int options)
 {
        if (getState() != State::Unencrypted) {
                INFO(SINK, "Cannot encrypt, SD card's state incorrect.");
-               return -1;
+               return error::NoSuchDevice;
        }
 
        KeyManager::data pwData(password.begin(), password.end());
@@ -298,7 +299,7 @@ int ExternalEncryptionServer::encrypt(const std::string &password, unsigned int
 
        if (!keyManager.verifyPassword(pwData)) {
                ERROR(SINK, "Wrong password passed.");
-               return -2;
+               return error::WrongPassword;
        }
 
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
@@ -326,14 +327,14 @@ int ExternalEncryptionServer::encrypt(const std::string &password, unsigned int
        std::thread asyncWork(encryptWorker);
        asyncWork.detach();
 
-       return 0;
+       return error::None;
 }
 
 int ExternalEncryptionServer::decrypt(const std::string &password)
 {
        if (getState() != State::Encrypted) {
                ERROR(SINK, "Cannot decrypt, SD card's state incorrect.");
-               return -1;
+               return error::NoSuchDevice;
        }
 
        KeyManager::data pwData(password.begin(), password.end());
@@ -341,7 +342,7 @@ int ExternalEncryptionServer::decrypt(const std::string &password)
 
        if (!keyManager.verifyPassword(pwData)) {
                ERROR(SINK, "Wrong password passed.");
-               return -2;
+               return error::WrongPassword;
        }
 
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
@@ -377,13 +378,13 @@ int ExternalEncryptionServer::decrypt(const std::string &password)
        std::thread asyncWork(decryptWorker);
        asyncWork.detach();
 
-       return 0;
+       return error::None;
 }
 
 int ExternalEncryptionServer::recovery()
 {
        if (getState() == State::Unencrypted) {
-               return -1;
+               return error::NoSuchDevice;
        }
 
        for (runtime::DirectoryIterator iter(engine->getSource()), end;
@@ -394,15 +395,15 @@ int ExternalEncryptionServer::recovery()
        engine->clearKeyMeta();
        ::vconf_set_str(VCONFKEY_SDE_CRYPTO_STATE, "unencrypted");
 
-       return 0;
+       return error::None;
 }
 
 int ExternalEncryptionServer::isPasswordInitialized()
 {
        if (engine->isKeyMetaSet()) {
-               return 1;
+               return error::None;
        }
-       return 0;
+       return error::NoSuchFile;
 }
 
 int ExternalEncryptionServer::initPassword(const std::string& password)
@@ -412,7 +413,7 @@ int ExternalEncryptionServer::initPassword(const std::string& password)
 
        keyManager.initPassword(pwData);
        engine->setKeyMeta(keyManager.serialize());
-       return 0;
+       return error::None;
 }
 
 int ExternalEncryptionServer::cleanPassword(const std::string& password)
@@ -422,11 +423,11 @@ int ExternalEncryptionServer::cleanPassword(const std::string& password)
 
        if (!keyManager.verifyPassword(pwData)) {
                ERROR(SINK, "Wrong password passed.");
-               return -2;
+               return error::WrongPassword;
        }
 
        engine->clearKeyMeta();
-       return 0;
+       return error::None;
 }
 
 int ExternalEncryptionServer::changePassword(const std::string &oldPassword,
@@ -438,13 +439,13 @@ int ExternalEncryptionServer::changePassword(const std::string &oldPassword,
 
        if (!keyManager.verifyPassword(oldPwData)) {
                ERROR(SINK, "Wrong password passed.");
-               return -2;
+               return error::WrongPassword;
        }
 
        keyManager.changePassword(oldPwData, newPwData);
        engine->setKeyMeta(keyManager.serialize());
 
-       return 0;
+       return error::None;
 }
 
 int ExternalEncryptionServer::verifyPassword(const std::string& password)
@@ -453,9 +454,9 @@ int ExternalEncryptionServer::verifyPassword(const std::string& password)
        KeyManager keyManager(engine->getKeyMeta());
 
        if (keyManager.verifyPassword(pwData)) {
-               return 1;
+               return error::None;
        }
-       return 0;
+       return error::WrongPassword;
 }
 
 int ExternalEncryptionServer::getState()
@@ -475,8 +476,6 @@ int ExternalEncryptionServer::getState()
        } else {
                return State::Corrupted;
        }
-
-       return 0;
 }
 
 unsigned int ExternalEncryptionServer::getSupportedOptions()
index 77da03b..6bb2b28 100644 (file)
@@ -37,6 +37,7 @@
 #include "misc.h"
 #include "logger.h"
 #include "progress-bar.h"
+#include "rmi/common.h"
 
 #include "internal-encryption.h"
 
@@ -270,19 +271,19 @@ int InternalEncryptionServer::setMountPassword(const std::string& password)
        KeyManager keyManager(engine->getKeyMeta());
        if (!keyManager.verifyPassword(pwData)) {
                ERROR(SINK, "Wrong password passed.");
-               return -2;
+               return error::WrongPassword;
        }
 
        mountKey = keyManager.getMasterKey(pwData);
 
-       return 0;
+       return error::None;
 }
 
 int InternalEncryptionServer::mount()
 {
        if (mountKey.empty()) {
                ERROR(SINK, "You need to call set_mount_password() first.");
-               return -1;
+               return error::NoData;
        }
 
        KeyManager::data key = mountKey;
@@ -290,12 +291,12 @@ int InternalEncryptionServer::mount()
 
        if (getState() != State::Encrypted) {
                INFO(SINK, "Cannot mount, SD partition's state incorrect.");
-               return -1;
+               return error::NoSuchDevice;
        }
 
-    if (engine->isMounted()) {
+       if (engine->isMounted()) {
                INFO(SINK, "Partition already mounted.");
-               return 0;
+               return error::None;
        }
 
        INFO(SINK, "Mounting internal storage.");
@@ -308,22 +309,22 @@ int InternalEncryptionServer::mount()
                runtime::File("/tmp/.unlock_mnt").create(O_WRONLY);
        } catch (runtime::Exception &e) {
                ERROR(SINK, "Mount failed: " + std::string(e.what()));
-               return -1;
+               return error::Unknown;
        }
 
-       return 0;
+       return error::None;
 }
 
 int InternalEncryptionServer::umount()
 {
        if (getState() != State::Encrypted) {
                ERROR(SINK, "Cannot umount, partition's state incorrect.");
-               return -1;
+               return error::NoSuchDevice;
        }
 
        if (!engine->isMounted()) {
                INFO(SINK, "Partition already umounted.");
-               return 0;
+               return error::None;
        }
 
        INFO(SINK, "Closing all processes using internal storage.");
@@ -333,17 +334,17 @@ int InternalEncryptionServer::umount()
                engine->umount();
        } catch (runtime::Exception &e) {
                ERROR(SINK, "Umount failed: " + std::string(e.what()));
-               return -1;
+               return error::Unknown;
        }
 
-       return 0;
+       return error::None;
 }
 
 int InternalEncryptionServer::encrypt(const std::string& password, unsigned int options)
 {
        if (getState() != State::Unencrypted) {
                ERROR(SINK, "Cannot encrypt, partition's state incorrect.");
-               return -1;
+               return error::NoSuchDevice;
        }
 
        KeyManager::data pwData(password.begin(), password.end());
@@ -351,7 +352,7 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int
 
        if (!keyManager.verifyPassword(pwData)) {
                ERROR(SINK, "Wrong password passed.");
-               return -2;
+               return error::WrongPassword;
        }
 
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
@@ -400,14 +401,14 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int
        std::thread asyncWork(encryptWorker);
        asyncWork.detach();
 
-       return 0;
+       return error::None;
 }
 
 int InternalEncryptionServer::decrypt(const std::string& password)
 {
        if (getState() != State::Encrypted) {
                ERROR(SINK, "Cannot decrypt, partition's state incorrect.");
-               return -1;
+               return error::NoSuchDevice;
        }
 
        KeyManager::data pwData(password.begin(), password.end());
@@ -415,7 +416,7 @@ int InternalEncryptionServer::decrypt(const std::string& password)
 
        if (!keyManager.verifyPassword(pwData)) {
                ERROR(SINK, "Wrong password passed.");
-               return -2;
+               return error::WrongPassword;
        }
 
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
@@ -458,31 +459,31 @@ int InternalEncryptionServer::decrypt(const std::string& password)
        std::thread asyncWork(decryptWorker);
        asyncWork.detach();
 
-       return 0;
+       return error::None;
 }
 
 int InternalEncryptionServer::recovery()
 {
-       if (getState() != State::Unencrypted) {
-               return -1;
+       if (getState() == State::Unencrypted) {
+               return error::NoSuchDevice;
        }
 
        //TODO
        runtime::Process proc(PROG_FACTORY_RESET, wipeCommand);
        if (proc.execute() == -1) {
                ERROR(SINK, "Failed to launch factory-reset");
-               return -2;
+               return error::WrongPassword;
        }
 
-       return 0;
+       return error::None;
 }
 
 int InternalEncryptionServer::isPasswordInitialized()
 {
        if (engine->isKeyMetaSet()) {
-               return 1;
+               return error::None;
        }
-       return 0;
+       return error::NoSuchFile;
 }
 
 int InternalEncryptionServer::initPassword(const std::string& password)
@@ -492,7 +493,7 @@ int InternalEncryptionServer::initPassword(const std::string& password)
 
        keyManager.initPassword(pwData);
        engine->setKeyMeta(keyManager.serialize());
-       return 0;
+       return error::None;
 }
 
 int InternalEncryptionServer::cleanPassword(const std::string& password)
@@ -502,11 +503,11 @@ int InternalEncryptionServer::cleanPassword(const std::string& password)
 
        if (!keyManager.verifyPassword(pwData)) {
                ERROR(SINK, "Wrong password passed.");
-               return -2;
+               return error::WrongPassword;
        }
 
        engine->clearKeyMeta();
-       return 0;
+       return error::None;
 }
 
 int InternalEncryptionServer::changePassword(const std::string& oldPassword,
@@ -518,13 +519,13 @@ int InternalEncryptionServer::changePassword(const std::string& oldPassword,
 
        if (!keyManager.verifyPassword(oldPwData)) {
                ERROR(SINK, "Wrong password passed.");
-               return -2;
+               return error::WrongPassword;
        }
 
        keyManager.changePassword(oldPwData, newPwData);
        engine->setKeyMeta(keyManager.serialize());
 
-       return 0;
+       return error::None;
 }
 
 int InternalEncryptionServer::verifyPassword(const std::string& password)
@@ -533,9 +534,9 @@ int InternalEncryptionServer::verifyPassword(const std::string& password)
        KeyManager keyManager(engine->getKeyMeta());
 
        if (keyManager.verifyPassword(pwData)) {
-               return 1;
+               return error::None;
        }
-       return 0;
+       return error::WrongPassword;
 }
 
 int InternalEncryptionServer::getState()
@@ -555,8 +556,6 @@ int InternalEncryptionServer::getState()
        } else {
                return State::Corrupted;
        }
-
-       return 0;
 }
 
 unsigned int InternalEncryptionServer::getSupportedOptions()
index aea9b7e..4690cbe 100644 (file)
@@ -31,18 +31,18 @@ const char *PRIVILEGE_PLATFORM = "http://tizen.org/privilege/internal/default/pl
 const size_t DEFAULT_KEY_SIZE = 64;
 
 std::map<Luks::Operation, std::string> OPERATION_NAME = {
-               { Luks::Format, "Formatting" },
-               { Luks::Open,   "Opening" },
-               { Luks::Close,  "Closing" },
+       { Luks::Format, "Formatting" },
+       { Luks::Open,   "Opening" },
+       { Luks::Close,  "Closing" },
 };
 
-std::map<CryptsetupEngine::ReturnCode, OdeError> CRYPTSETUP_ERROR_2_ODE_ERROR = {
-               { CryptsetupEngine::ReturnCode::SUCCESS, OdeError::None },
-               { CryptsetupEngine::ReturnCode::WRONG_PARAMS, OdeError::InvalidParameter },
-               { CryptsetupEngine::ReturnCode::NO_PERMISSION, OdeError::WrongPassword },
-               { CryptsetupEngine::ReturnCode::OUT_OF_MEMORY, OdeError::OutOfMemory },
-               { CryptsetupEngine::ReturnCode::WRONG_DEVICE, OdeError::NoSuchFile },
-               { CryptsetupEngine::ReturnCode::DEVICE_BUSY, OdeError::DeviceBusy }
+std::map<CryptsetupEngine::ReturnCode, int> CRYPTSETUP_ERROR_2_ODE_ERROR = {
+       { CryptsetupEngine::ReturnCode::SUCCESS, error::None },
+       { CryptsetupEngine::ReturnCode::WRONG_PARAMS, error::InvalidParameter },
+       { CryptsetupEngine::ReturnCode::NO_PERMISSION, error::WrongPassword },
+       { CryptsetupEngine::ReturnCode::OUT_OF_MEMORY, error::OutOfMemory },
+       { CryptsetupEngine::ReturnCode::WRONG_DEVICE, error::NoSuchFile },
+       { CryptsetupEngine::ReturnCode::DEVICE_BUSY, error::DeviceBusy }
 };
 
 } // anonymous namespace
@@ -64,7 +64,7 @@ template <typename F>
 int LuksServer::execute(bool sync, Luks::Operation op, const F& job)
 {
        auto worker = [=]() {
-               OdeError ret = OdeError::Unknown;
+               int ret = error::Unknown;
                try {
                        std::lock_guard<std::mutex> guardLock(opGuard);
                        ret = job();
@@ -77,17 +77,17 @@ int LuksServer::execute(bool sync, Luks::Operation op, const F& job)
                } catch (const std::exception& e) {
                        ERROR(SINK, OPERATION_NAME.at(op) + " thread failed: " +
                                        std::string(e.what()));
-                       ret = OdeError::Unknown;
+                       ret = error::Unknown;
                } catch (...) {
                        ERROR(SINK, OPERATION_NAME.at(op) +
                                        " thread failed: unknown exception.");
-                       ret = OdeError::Unknown;
+                       ret = error::Unknown;
                }
                if (sync) {
-                       return static_cast<int>(ret);
+                       return ret;
                } else {
-                       server.notify(NOTIFICATION, static_cast<int>(op), static_cast<int>(ret));
-                       return 0;
+                       server.notify(NOTIFICATION, static_cast<int>(op), ret);
+                       return error::None;
                }
        };
 
@@ -96,7 +96,7 @@ int LuksServer::execute(bool sync, Luks::Operation op, const F& job)
        } else {
                std::thread work(worker);
                work.detach();
-               return 0;
+               return error::None;
        }
 }
 
@@ -114,7 +114,7 @@ int LuksServer::format(bool sync,
 
                engine.format(CryptsetupEngine::DeviceType::LUKS,
                                          keyManager.getMasterKey(pwData));
-               return OdeError::None;
+               return error::None;
        });
 }
 
@@ -131,12 +131,12 @@ int LuksServer::open(bool sync,
 
                if (!keyManager.verifyPassword(pwData)) {
                        ERROR(SINK, "Wrong password passed.");
-                       return OdeError::WrongPassword;
+                       return error::WrongPassword;
                }
 
                KeyManager::data masterKey = keyManager.getMasterKey(pwData);
                engine.open(CryptsetupEngine::DeviceType::LUKS, mapping, masterKey);
-               return OdeError::None;
+               return error::None;
        });
 }
 
@@ -145,7 +145,7 @@ int LuksServer::close(bool sync,
 {
        return execute(sync, Luks::Close, [=](){
                CryptsetupEngine::close(mapping);
-               return OdeError::None;
+               return error::None;
        });
 }
 
index e7a66cb..025c2a2 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "misc.h"
 #include "secure-erase.h"
+#include "rmi/common.h"
 
 namespace ode {
 
@@ -75,7 +76,7 @@ int SecureEraseServer::clean(const std::string &name)
 
        std::thread asyncWork(cleanWorker);
        asyncWork.detach();
-       return 0;
+       return error::None;
 }
 
 } // namespace ode