Change DBCrypto return type
authorZofia Abramowska <z.abramowska@samsung.com>
Tue, 10 Jun 2014 10:15:45 +0000 (12:15 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Fri, 12 Sep 2014 12:57:27 +0000 (14:57 +0200)
Switch from custom enum to key-manager API error codes.

Change-Id: If0023d880c47516bbbc1d9ed911b19af4fee0c23

src/include/ckm/ckm-error.h
src/manager/common/db-crypto.cpp
src/manager/common/db-crypto.h

index 9af1ce4..c11afe1 100644 (file)
 /*! \brief   indicating the database was not unlocked - user did not login */
 #define KEY_MANAGER_API_ERROR_DB_LOCKED -12
 
+/*! \brief   indicating that request give to database returned no result */
+#define KEY_MANAGER_API_ERROR_DB_BAD_REQUEST -13
+
+/*! \brief   indicating an internal error inside the database */
+#define KEY_MANAGER_API_ERROR_DB_ERROR -14
+
 /*! \brief   indicating the error with unknown reason */
 #define KEY_MANAGER_API_ERROR_UNKNOWN -255
 /** @}*/
index ec983da..89f8778 100644 (file)
@@ -23,6 +23,7 @@
 #include <db-crypto.h>
 #include <dpl/db/sql_connection.h>
 #include <dpl/log/log.h>
+#include <ckm/ckm-error.h>
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic warning "-Wdeprecated-declarations"
@@ -124,9 +125,9 @@ using namespace DB;
         }
     }
 
-    DBCryptoReturn DBCrypto::saveDBRow(const DBRow &row){
+    int DBCrypto::saveDBRow(const DBRow &row){
         if(!m_init)
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         Try {
             SqlConnection::DataCommandAutoPtr insertCommand =
                     m_connection->PrepareDataCommand(insert_cmd);
@@ -145,20 +146,20 @@ using namespace DB;
                     "Insert statement should not return any row");
         } Catch(SqlConnection::Exception::SyntaxError) {
             LogError("Couldn't prepare insert statement");
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         } Catch(SqlConnection::Exception::InternalError) {
             LogError("Couldn't execute insert statement");
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         }
 
-        return DBCryptoReturn::DBCRYPTO_SUCCESS;
+        return KEY_MANAGER_API_SUCCESS;
     }
 
-    DBCryptoReturn DBCrypto::getDBRow(const Alias &alias,
+    int DBCrypto::getDBRow(const Alias &alias,
                                                    DBRow &row) {
 
         if(!m_init)
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         Try {
         SqlConnection::DataCommandAutoPtr selectCommand =
                 m_connection->PrepareDataCommand(select_alias_cmd);
@@ -176,25 +177,25 @@ using namespace DB;
             row.dataSize = selectCommand->GetColumnInteger(9);
             row.data = selectCommand->GetColumnBlob(10);
         } else {
-            return DBCryptoReturn::DBCRYPTO_ERROR_NO_ROW;
+            return KEY_MANAGER_API_ERROR_BAD_REQUEST;
         }
 
         AssertMsg(!selectCommand->Step(),
                 "Select returned multiple rows for unique column.");
         } Catch (SqlConnection::Exception::InvalidColumn) {
             LogError("Select statement invalid column error");
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         } Catch (SqlConnection::Exception::SyntaxError) {
             LogError("Couldn't prepare select statement");
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         } Catch (SqlConnection::Exception::InternalError) {
             LogError("Couldn't execute select statement");
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         }
-        return DBCryptoReturn::DBCRYPTO_SUCCESS;
+        return KEY_MANAGER_API_SUCCESS;
     }
 
-    DBCryptoReturn DBCrypto::getSingleType(DBDataType type, const std::string& label,
+    int DBCrypto::getSingleType(DBDataType type, const std::string& label,
             AliasVector& aliases) {
         Try{
             SqlConnection::DataCommandAutoPtr selectCommand =
@@ -210,36 +211,36 @@ using namespace DB;
             }
         } Catch (SqlConnection::Exception::InvalidColumn) {
             LogError("Select statement invalid column error");
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         } Catch (SqlConnection::Exception::SyntaxError) {
             LogError("Couldn't prepare select statement");
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         } Catch (SqlConnection::Exception::InternalError) {
             LogError("Couldn't execute select statement");
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         }
-        return DBCryptoReturn::DBCRYPTO_SUCCESS;
+        return KEY_MANAGER_API_SUCCESS;
     }
 
-    DBCryptoReturn DBCrypto::getAliases(DBQueryType type, const std::string& label,
+    int DBCrypto::getAliases(DBQueryType type, const std::string& label,
             AliasVector& aliases) {
 
         if(!m_init)
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
-        DBCryptoReturn ret;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
+        int ret;
         switch(type) {
         case DBQueryType::KEY_QUERY:
             ret = getSingleType(DBDataType::KEY_AES, label, aliases);
-            if(ret != DBCryptoReturn::DBCRYPTO_SUCCESS)
+            if(ret != KEY_MANAGER_API_SUCCESS)
                 return ret;
             ret = getSingleType(DBDataType::KEY_ECDSA_PRIVATE, label, aliases);
-            if(ret != DBCryptoReturn::DBCRYPTO_SUCCESS)
+            if(ret != KEY_MANAGER_API_SUCCESS)
                 return ret;
             ret = getSingleType(DBDataType::KEY_ECDSA_PUBLIC, label, aliases);
-            if(ret != DBCryptoReturn::DBCRYPTO_SUCCESS)
+            if(ret != KEY_MANAGER_API_SUCCESS)
                 return ret;
             ret = getSingleType(DBDataType::KEY_RSA_PRIVATE, label, aliases);
-            if(ret != DBCryptoReturn::DBCRYPTO_SUCCESS)
+            if(ret != KEY_MANAGER_API_SUCCESS)
                 return ret;
             return(getSingleType(DBDataType::KEY_RSA_PUBLIC, label, aliases));
         case DBQueryType::CERTIFICATE_QUERY:
@@ -247,10 +248,10 @@ using namespace DB;
         case DBQueryType::BINARY_DATA_QUERY:
             return getSingleType(DBDataType::BINARY_DATA, label, aliases);
         }
-        return DBCryptoReturn::DBCRYPTO_SUCCESS;
+        return KEY_MANAGER_API_SUCCESS;
     }
 
-    DBCryptoReturn DBCrypto::deleteAlias(const Alias &alias) {
+    int DBCrypto::deleteAlias(const Alias &alias) {
         Try {
             SqlConnection::DataCommandAutoPtr deleteCommand =
                     m_connection->PrepareDataCommand(delete_alias_cmd);
@@ -258,12 +259,12 @@ using namespace DB;
             deleteCommand->Step();
         } Catch (SqlConnection::Exception::SyntaxError) {
             LogError("Couldn't prepare delete statement");
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         } Catch (SqlConnection::Exception::InternalError) {
             LogError("Couldn't execute delete statement");
-            return DBCryptoReturn::DBCRYPTO_ERROR_INTERNAL;
+            return KEY_MANAGER_API_ERROR_DB_ERROR;
         }
-        return DBCryptoReturn::DBCRYPTO_SUCCESS;
+        return KEY_MANAGER_API_SUCCESS;
     }
 
 } // CKM
index c39261a..9e279dc 100644 (file)
@@ -42,12 +42,7 @@ namespace CKM {
         int dataSize;               // size of information without hash and padding
         RawBuffer data;
     };
-    enum class DBCryptoReturn : int {
-        DBCRYPTO_SUCCESS = 0,
-        DBCRYPTO_ERROR_NO_ROW,
-        DBCRYPTO_ERROR_INTERNAL,
-        DBCRYPTO_ERROR_INVALID_ARGUMENTS
-    };
+
     class DBCrypto {
          public:
             DBCrypto() : m_connection(NULL), m_init(false) {};
@@ -63,11 +58,11 @@ namespace CKM {
             ~DBCrypto();
 
             bool isInit() {return m_init;};
-            DBCryptoReturn saveDBRow(const DBRow &row);
-            DBCryptoReturn getDBRow(const Alias &alias, DBRow& row);
-            DBCryptoReturn getAliases(DBQueryType dataType, const std::string &label,
+            int saveDBRow(const DBRow &row);
+            int getDBRow(const Alias &alias, DBRow& row);
+            int getAliases(DBQueryType dataType, const std::string &label,
                     AliasVector &aliases);
-            DBCryptoReturn deleteAlias(const Alias& alias);
+            int deleteAlias(const Alias& alias);
 
          private:
             DB::SqlConnection* m_connection;
@@ -75,7 +70,7 @@ namespace CKM {
 
             void initDatabase();
             bool checkTableExist(const std::string& table);
-            DBCryptoReturn getSingleType(DBDataType type, const std::string& label,
+            int getSingleType(DBDataType type, const std::string& label,
                     AliasVector& aliases);
 
    };