Commit 3af3a37a authored by Sandro Knauß's avatar Sandro Knauß

Refactor error handling for signatures

parent e0955ea1
...@@ -1870,20 +1870,9 @@ void CryptoMessagePart::startDecryption(KMime::Content *data) ...@@ -1870,20 +1870,9 @@ void CryptoMessagePart::startDecryption(KMime::Content *data)
bool CryptoMessagePart::okVerify(const QByteArray &data, const QByteArray &signature) bool CryptoMessagePart::okVerify(const QByteArray &data, const QByteArray &signature)
{ {
enum { NO_PLUGIN, NOT_INITIALIZED, CANT_VERIFY_SIGNATURES }
cryptPlugError = NO_PLUGIN;
QString cryptPlugLibName;
QString cryptPlugDisplayName;
NodeHelper *nodeHelper = mOtp->nodeHelper(); NodeHelper *nodeHelper = mOtp->nodeHelper();
ObjectTreeSourceIf *source = mOtp->mSource; ObjectTreeSourceIf *source = mOtp->mSource;
if (mCryptoProto) {
cryptPlugLibName = mCryptoProto->name();
cryptPlugDisplayName = mCryptoProto->displayName();
}
mMetaData.isSigned = false; mMetaData.isSigned = false;
mMetaData.technicalProblem = (mCryptoProto == 0); mMetaData.technicalProblem = (mCryptoProto == 0);
mMetaData.keyTrust = GpgME::Signature::Unknown; mMetaData.keyTrust = GpgME::Signature::Unknown;
...@@ -1893,23 +1882,18 @@ bool CryptoMessagePart::okVerify(const QByteArray &data, const QByteArray &signa ...@@ -1893,23 +1882,18 @@ bool CryptoMessagePart::okVerify(const QByteArray &data, const QByteArray &signa
const QByteArray mementoName = "verification"; const QByteArray mementoName = "verification";
CryptoBodyPartMemento *m = dynamic_cast<CryptoBodyPartMemento *>(nodeHelper->bodyPartMemento(mNode, mementoName)); CryptoBodyPartMemento *m = dynamic_cast<CryptoBodyPartMemento *>(nodeHelper->bodyPartMemento(mNode, mementoName));
assert(!m || mCryptoProto); //No CryptoPlugin and having a bodyPartMemento -> there is something completly wrong
if (!m) { if (!m && mCryptoProto) {
if (!signature.isEmpty()) { if (!signature.isEmpty()) {
Kleo::VerifyDetachedJob *job = mCryptoProto->verifyDetachedJob(); Kleo::VerifyDetachedJob *job = mCryptoProto->verifyDetachedJob();
if (job) { if (job) {
m = new VerifyDetachedBodyPartMemento(job, mCryptoProto->keyListJob(), signature, data); m = new VerifyDetachedBodyPartMemento(job, mCryptoProto->keyListJob(), signature, data);
} else {
cryptPlugError = CANT_VERIFY_SIGNATURES;
mCryptoProto = 0;
} }
} else { } else {
Kleo::VerifyOpaqueJob *job = mCryptoProto->verifyOpaqueJob(); Kleo::VerifyOpaqueJob *job = mCryptoProto->verifyOpaqueJob();
if (job) { if (job) {
m = new VerifyOpaqueBodyPartMemento(job, mCryptoProto->keyListJob(), data); m = new VerifyOpaqueBodyPartMemento(job, mCryptoProto->keyListJob(), data);
} else {
cryptPlugError = CANT_VERIFY_SIGNATURES;
mCryptoProto = 0;
} }
} }
if (m) { if (m) {
...@@ -1931,7 +1915,6 @@ bool CryptoMessagePart::okVerify(const QByteArray &data, const QByteArray &signa ...@@ -1931,7 +1915,6 @@ bool CryptoMessagePart::okVerify(const QByteArray &data, const QByteArray &signa
} else if (m->isRunning()) { } else if (m->isRunning()) {
mMetaData.inProgress = true; mMetaData.inProgress = true;
mOtp->mHasPendingAsyncJobs = true; mOtp->mHasPendingAsyncJobs = true;
m = 0;
} else { } else {
mMetaData.inProgress = false; mMetaData.inProgress = false;
mOtp->mHasPendingAsyncJobs = false; mOtp->mHasPendingAsyncJobs = false;
...@@ -1952,18 +1935,16 @@ bool CryptoMessagePart::okVerify(const QByteArray &data, const QByteArray &signa ...@@ -1952,18 +1935,16 @@ bool CryptoMessagePart::okVerify(const QByteArray &data, const QByteArray &signa
mMetaData.isSigned = !mSignatures.empty(); mMetaData.isSigned = !mSignatures.empty();
} }
if (!mCryptoProto) { if (!m && !mMetaData.inProgress) {
QString errorMsg; QString errorMsg;
switch (cryptPlugError) { QString cryptPlugLibName;
case NOT_INITIALIZED: QString cryptPlugDisplayName;
errorMsg = i18n("Crypto plug-in \"%1\" is not initialized.", if (mCryptoProto) {
cryptPlugLibName); cryptPlugLibName = mCryptoProto->name();
break; cryptPlugDisplayName = mCryptoProto->displayName();
case CANT_VERIFY_SIGNATURES: }
errorMsg = i18n("Crypto plug-in \"%1\" cannot verify mSignatures.",
cryptPlugLibName); if (!mCryptoProto) {
break;
case NO_PLUGIN:
if (cryptPlugDisplayName.isEmpty()) { if (cryptPlugDisplayName.isEmpty()) {
errorMsg = i18n("No appropriate crypto plug-in was found."); errorMsg = i18n("No appropriate crypto plug-in was found.");
} else { } else {
...@@ -1971,7 +1952,9 @@ bool CryptoMessagePart::okVerify(const QByteArray &data, const QByteArray &signa ...@@ -1971,7 +1952,9 @@ bool CryptoMessagePart::okVerify(const QByteArray &data, const QByteArray &signa
"No %1 plug-in was found.", "No %1 plug-in was found.",
cryptPlugDisplayName); cryptPlugDisplayName);
} }
break; } else {
errorMsg = i18n("Crypto plug-in \"%1\" cannot verify mSignatures.",
cryptPlugLibName);
} }
mMetaData.errorText = i18n("The message is signed, but the " mMetaData.errorText = i18n("The message is signed, but the "
"validity of the signature cannot be " "validity of the signature cannot be "
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment