diff options
| -rw-r--r-- | crypt/cryptexception.cpp | 4 | ||||
| -rw-r--r-- | crypt/cryptexception.h | 20 | ||||
| -rw-r--r-- | crypt/hybridcrypt.cpp | 10 |
3 files changed, 24 insertions, 10 deletions
diff --git a/crypt/cryptexception.cpp b/crypt/cryptexception.cpp index 4cf2e6c..d839029 100644 --- a/crypt/cryptexception.cpp +++ b/crypt/cryptexception.cpp @@ -1,6 +1,6 @@ #include "cryptexception.h" -CryptException::CryptException(std::string what, int returnCode) +CryptException::CryptException(std::string what, ReturnCode returnCode) :exception() { this->whatMsg = what; @@ -17,7 +17,7 @@ const char *CryptException::what() const throw() return whatMsg.c_str(); } -int CryptException::returnCode() const +CryptException::ReturnCode CryptException::returnCode() const { return retId; } diff --git a/crypt/cryptexception.h b/crypt/cryptexception.h index 1141969..7f70211 100644 --- a/crypt/cryptexception.h +++ b/crypt/cryptexception.h @@ -2,18 +2,32 @@ #define CRYPTEXCEPTION_H #include <exception> + #include <QString> class CryptException : public std::exception { public: /** + * @brief The ReturnCode enum + */ + enum ReturnCode + { + FileNotFound = 1, + FileNotWritable, + DecryptionErrorRsa, + DecryptionErrorAes, + OpenSslError, + KeyNotRsa + }; + + /** * @brief CryptException * Erzeugt eine Exception mit den angegebenen Werten. * @param what Die Fehlermeldung, die dem Nutzer gezeigt wird. * @param returnCode Der Rückgabewert für die Konsole. */ - CryptException(std::string what, int returnCode); + CryptException(std::string what, ReturnCode returnCode); /** * @brief ~CryptException @@ -32,11 +46,11 @@ public: * Gibt den Konsolenrückgabewert zurück. * @return Der Rückgabewert für die Konsole. */ - int returnCode() const; + ReturnCode returnCode() const; private: std::string whatMsg; - int retId; + ReturnCode retId; }; diff --git a/crypt/hybridcrypt.cpp b/crypt/hybridcrypt.cpp index c408bf1..9c236cb 100644 --- a/crypt/hybridcrypt.cpp +++ b/crypt/hybridcrypt.cpp @@ -99,7 +99,7 @@ void HybridCrypt::importUserKeypair(QString keyfileName, QString password) // Datei existiert nicht if (keyfile == NULL) { - throw CryptException("Datei nicht gefunden: " + keyfileName.toStdString(), 1); + throw CryptException("Datei nicht gefunden: " + keyfileName.toStdString(), CryptException::FileNotFound); } // Ließ den Schlüssel des Nutzers ein @@ -129,7 +129,7 @@ void HybridCrypt::exportUserKeypair(QString keyfileName, QString password) if (keyfile == NULL) { throw CryptException("Konnte Datei nicht schreiben: " + - keyfileName.toStdString(), 1); + keyfileName.toStdString(), CryptException::FileNotWritable); } // Wenn password ein Leerstring ist, verschlüssele den privaten Schlüssel nicht @@ -158,7 +158,7 @@ void HybridCrypt::exportPublicUserKey(QString keyfileName) if (keyfile == NULL) { throw CryptException("Konnte Datei nicht schreiben: " + - keyfileName.toStdString(), 1); + keyfileName.toStdString(), CryptException::FileNotWritable); } int opensslReturnError = PEM_write_PUBKEY(keyfile, userKeypair); @@ -192,7 +192,7 @@ void HybridCrypt::throwOpenSslException() { QString errorMsg("OpenSSL Fehler. Fehlermeldung: "); errorMsg.append(ERR_error_string(ERR_get_error(), NULL)); - throw CryptException(errorMsg.toStdString(), 5); + throw CryptException(errorMsg.toStdString(), CryptException::OpenSslError); } void HybridCrypt::throwExceptionIfEvpKeyIsNotRsa(EVP_PKEY **key) @@ -200,7 +200,7 @@ void HybridCrypt::throwExceptionIfEvpKeyIsNotRsa(EVP_PKEY **key) if (!isKeyRsa(*key)) { freeEvpKey(key); - throw CryptException("Nur RSA Schlüssel werden unterstüzt.", 6); + throw CryptException("Nur RSA Schlüssel werden unterstüzt.", CryptException::KeyNotRsa); } } |
