1
0
mirror of https://github.com/QRouland/UTPass.git synced 2026-01-10 03:26:57 +00:00

Improve Lib Pass Error Messages

This commit is contained in:
2025-03-14 10:07:05 +01:00
parent bdb2d58ac4
commit dc2c35ca9b
7 changed files with 92 additions and 53 deletions

View File

@@ -6,25 +6,66 @@ extern "C" {
#include "rnp/rnp_err.h"
}
enum ErrorCodeShow {
UnexceptedError= 1,
enum class ErrorCodeShow {
Success= 0,
UnexceptedError,
BadPassphrase,
NoKeyFound,
DecryptFailed
};
ErrorCodeShow rnpErrorToErrorCodeShow(int rnpErrorCode) {
int rnpErrorToErrorCodeShow(int rnpErrorCode) {
switch (rnpErrorCode) {
case RNP_SUCCESS:
return static_cast<int>(ErrorCodeShow::Success);
case RNP_ERROR_BAD_PASSWORD:
return BadPassphrase;
return static_cast<int>(ErrorCodeShow::BadPassphrase);
case RNP_ERROR_KEY_NOT_FOUND:
case RNP_ERROR_NO_SUITABLE_KEY:
return NoKeyFound;
return static_cast<int>(ErrorCodeShow::NoKeyFound);
case RNP_ERROR_DECRYPT_FAILED:
return DecryptFailed;
return static_cast<int>(ErrorCodeShow::DecryptFailed);
default:
return UnexceptedError;
return static_cast<int>(ErrorCodeShow::UnexceptedError);
}
}
enum class ErrorCodeImportKeyFile {
Success= 0,
UnexceptedError,
BadFormat,
};
int rnpErrorToErrorCodeImportKeyFile(int rnpErrorCode) {
switch (rnpErrorCode) {
case RNP_SUCCESS:
return static_cast<int>(ErrorCodeShow::Success);
case RNP_ERROR_BAD_FORMAT:
return static_cast<int>(ErrorCodeImportKeyFile::BadFormat);
default:
return static_cast<int>(ErrorCodeImportKeyFile::UnexceptedError);
}
}
enum class ErrorCodeUnexvepted {
Success= 0,
UnexceptedError,
};
int rnpErrorToErrorCodeGeneric(int rnpErrorCode) {
switch (rnpErrorCode) {
case RNP_SUCCESS:
return static_cast<int>(ErrorCodeShow::Success);
default:
return static_cast<int>(ErrorCodeImportKeyFile::UnexceptedError);
}
}
enum class ErrorCode
{
Success= 0,
Error,
};
#endif // ERROR_H