2025-03-12 15:34:33 +01:00
|
|
|
// error.h
|
|
|
|
#ifndef ERROR_H
|
|
|
|
#define ERROR_H
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "rnp/rnp_err.h"
|
|
|
|
}
|
|
|
|
|
2025-03-14 10:07:05 +01:00
|
|
|
enum class ErrorCodeShow {
|
|
|
|
Success= 0,
|
|
|
|
UnexceptedError,
|
2025-03-12 15:34:33 +01:00
|
|
|
BadPassphrase,
|
|
|
|
NoKeyFound,
|
|
|
|
DecryptFailed
|
|
|
|
};
|
|
|
|
|
2025-03-14 10:07:05 +01:00
|
|
|
int rnpErrorToErrorCodeShow(int rnpErrorCode) {
|
2025-03-12 15:34:33 +01:00
|
|
|
switch (rnpErrorCode) {
|
2025-03-14 10:07:05 +01:00
|
|
|
case RNP_SUCCESS:
|
|
|
|
return static_cast<int>(ErrorCodeShow::Success);
|
2025-03-12 15:34:33 +01:00
|
|
|
case RNP_ERROR_BAD_PASSWORD:
|
2025-03-14 10:07:05 +01:00
|
|
|
return static_cast<int>(ErrorCodeShow::BadPassphrase);
|
2025-03-12 15:34:33 +01:00
|
|
|
case RNP_ERROR_KEY_NOT_FOUND:
|
|
|
|
case RNP_ERROR_NO_SUITABLE_KEY:
|
2025-03-14 10:07:05 +01:00
|
|
|
return static_cast<int>(ErrorCodeShow::NoKeyFound);
|
2025-03-12 15:34:33 +01:00
|
|
|
case RNP_ERROR_DECRYPT_FAILED:
|
2025-03-14 10:07:05 +01:00
|
|
|
return static_cast<int>(ErrorCodeShow::DecryptFailed);
|
2025-03-12 15:34:33 +01:00
|
|
|
default:
|
2025-03-14 10:07:05 +01:00
|
|
|
return static_cast<int>(ErrorCodeShow::UnexceptedError);
|
2025-03-12 15:34:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-03-14 10:07:05 +01:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2025-03-12 15:34:33 +01:00
|
|
|
#endif // ERROR_H
|