Return error if password is not empty and row is not password protected
[platform/core/security/key-manager.git] / src / manager / service / crypto-logic.cpp
index c7b8786..6fe6e4e 100644 (file)
@@ -208,13 +208,19 @@ void CryptoLogic::decryptRow(const Password &password, DB::Row &row)
 
         if ((row.encryptionScheme & ENCR_PASSWORD) && password.empty()) {
             ThrowErr(Exc::AuthenticationFailed,
-              "DB row is password protected, but given password is "
-              "empty.");
+                     "DB row is password protected, but given password is empty.");
+        }
+
+        if(!(row.encryptionScheme & ENCR_PASSWORD) && !password.empty()) {
+            ThrowErr(Exc::AuthenticationFailed,
+                     "DB row is not password protected, but given password is not empty.");
         }
 
         if ((row.encryptionScheme & ENCR_APPKEY) && !haveKey(row.ownerLabel)) {
-            ThrowErr(Exc::AuthenticationFailed, "Missing application key for ",
-              row.ownerLabel, " label.");
+            ThrowErr(Exc::AuthenticationFailed,
+                     "Missing application key for ",
+                     row.ownerLabel,
+                     " label.");
         }
 
         decBase64(crow.iv);