make OpenPgpSignatureResult immutable
This commit is contained in:
@@ -97,10 +97,6 @@ public class OpenPgpSignatureResultBuilder {
|
||||
this.mConfirmedUserIds = confirmedUserIds;
|
||||
}
|
||||
|
||||
public boolean isValidSignature() {
|
||||
return mValidSignature;
|
||||
}
|
||||
|
||||
public boolean isInsecure() {
|
||||
return mInsecure;
|
||||
}
|
||||
@@ -147,52 +143,41 @@ public class OpenPgpSignatureResultBuilder {
|
||||
}
|
||||
|
||||
public OpenPgpSignatureResult build() {
|
||||
OpenPgpSignatureResult result = new OpenPgpSignatureResult();
|
||||
|
||||
if (!mSignatureAvailable) {
|
||||
Log.d(Constants.TAG, "RESULT_NO_SIGNATURE");
|
||||
result.setResult(OpenPgpSignatureResult.RESULT_NO_SIGNATURE);
|
||||
return result;
|
||||
return OpenPgpSignatureResult.createWithNoSignature();
|
||||
}
|
||||
|
||||
if (!mKnownKey) {
|
||||
result.setKeyId(mKeyId);
|
||||
|
||||
Log.d(Constants.TAG, "RESULT_KEY_MISSING");
|
||||
result.setResult(OpenPgpSignatureResult.RESULT_KEY_MISSING);
|
||||
return result;
|
||||
return OpenPgpSignatureResult.createWithKeyMissing(mKeyId);
|
||||
}
|
||||
|
||||
if (!mValidSignature) {
|
||||
Log.d(Constants.TAG, "RESULT_INVALID_SIGNATURE");
|
||||
result.setResult(OpenPgpSignatureResult.RESULT_INVALID_SIGNATURE);
|
||||
return result;
|
||||
return OpenPgpSignatureResult.createWithInvalidSignature();
|
||||
}
|
||||
|
||||
result.setKeyId(mKeyId);
|
||||
result.setPrimaryUserId(mPrimaryUserId);
|
||||
result.setUserIds(mUserIds);
|
||||
result.setConfirmedUserIds(mConfirmedUserIds);
|
||||
result.setSenderResult(mSenderStatus);
|
||||
|
||||
int signatureStatus;
|
||||
if (mIsKeyRevoked) {
|
||||
Log.d(Constants.TAG, "RESULT_INVALID_KEY_REVOKED");
|
||||
result.setResult(OpenPgpSignatureResult.RESULT_INVALID_KEY_REVOKED);
|
||||
signatureStatus = OpenPgpSignatureResult.RESULT_INVALID_KEY_REVOKED;
|
||||
} else if (mIsKeyExpired) {
|
||||
Log.d(Constants.TAG, "RESULT_INVALID_KEY_EXPIRED");
|
||||
result.setResult(OpenPgpSignatureResult.RESULT_INVALID_KEY_EXPIRED);
|
||||
signatureStatus = OpenPgpSignatureResult.RESULT_INVALID_KEY_EXPIRED;
|
||||
} else if (mInsecure) {
|
||||
Log.d(Constants.TAG, "RESULT_INVALID_INSECURE");
|
||||
result.setResult(OpenPgpSignatureResult.RESULT_INVALID_INSECURE);
|
||||
signatureStatus = OpenPgpSignatureResult.RESULT_INVALID_INSECURE;
|
||||
} else if (mIsSignatureKeyCertified) {
|
||||
Log.d(Constants.TAG, "RESULT_VALID_CONFIRMED");
|
||||
result.setResult(OpenPgpSignatureResult.RESULT_VALID_CONFIRMED);
|
||||
signatureStatus = OpenPgpSignatureResult.RESULT_VALID_CONFIRMED;
|
||||
} else {
|
||||
Log.d(Constants.TAG, "RESULT_VALID_UNCONFIRMED");
|
||||
result.setResult(OpenPgpSignatureResult.RESULT_VALID_UNCONFIRMED);
|
||||
signatureStatus = OpenPgpSignatureResult.RESULT_VALID_UNCONFIRMED;
|
||||
}
|
||||
|
||||
return result;
|
||||
return OpenPgpSignatureResult.createWithValidSignature(
|
||||
signatureStatus, mPrimaryUserId, mKeyId, mUserIds, mConfirmedUserIds, mSenderStatus);
|
||||
}
|
||||
|
||||
public void setSenderAddress(String senderAddress) {
|
||||
|
||||
@@ -514,8 +514,6 @@ public class OpenPgpService extends Service {
|
||||
|
||||
OpenPgpSignatureResult signatureResult = pgpResult.getSignatureResult();
|
||||
|
||||
result.putExtra(OpenPgpApi.RESULT_SIGNATURE, signatureResult);
|
||||
|
||||
switch (signatureResult.getResult()) {
|
||||
case OpenPgpSignatureResult.RESULT_KEY_MISSING: {
|
||||
// If signature key is missing we return a PendingIntent to retrieve the key
|
||||
@@ -545,14 +543,14 @@ public class OpenPgpService extends Service {
|
||||
// RESULT_INVALID_KEY_REVOKED and RESULT_INVALID_KEY_EXPIRED have been added in version 5
|
||||
if (signatureResult.getResult() == OpenPgpSignatureResult.RESULT_INVALID_KEY_REVOKED
|
||||
|| signatureResult.getResult() == OpenPgpSignatureResult.RESULT_INVALID_KEY_EXPIRED) {
|
||||
signatureResult.setResult(OpenPgpSignatureResult.RESULT_INVALID_SIGNATURE);
|
||||
signatureResult = OpenPgpSignatureResult.createWithInvalidSignature();
|
||||
}
|
||||
}
|
||||
|
||||
if (data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) < 8) {
|
||||
// RESULT_INVALID_INSECURE has been added in version 8, fallback to RESULT_INVALID_SIGNATURE
|
||||
if (signatureResult.getResult() == OpenPgpSignatureResult.RESULT_INVALID_INSECURE) {
|
||||
signatureResult.setResult(OpenPgpSignatureResult.RESULT_INVALID_SIGNATURE);
|
||||
signatureResult = OpenPgpSignatureResult.createWithInvalidSignature();
|
||||
}
|
||||
|
||||
// RESULT_NO_SIGNATURE has been added in version 8, before the signatureResult was null
|
||||
@@ -568,7 +566,7 @@ public class OpenPgpService extends Service {
|
||||
if (decryptionResult.getResult() == OpenPgpDecryptionResult.RESULT_NOT_ENCRYPTED
|
||||
&& signatureResult.getResult() != OpenPgpSignatureResult.RESULT_NO_SIGNATURE) {
|
||||
// noinspection deprecation
|
||||
signatureResult.setSignatureOnly(true);
|
||||
signatureResult = signatureResult.withSignatureOnlyFlag();
|
||||
}
|
||||
|
||||
// case RESULT_INSECURE, simply accept as a fallback like in previous API versions
|
||||
@@ -597,6 +595,7 @@ public class OpenPgpService extends Service {
|
||||
result.putExtra(OpenPgpApi.RESULT_CHARSET, charset);
|
||||
}
|
||||
|
||||
result.putExtra(OpenPgpApi.RESULT_SIGNATURE, signatureResult);
|
||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
|
||||
return result;
|
||||
} else {
|
||||
|
||||
2
extern/openpgp-api-lib
vendored
2
extern/openpgp-api-lib
vendored
Submodule extern/openpgp-api-lib updated: 84fdd0c37d...4be4e488f2
Reference in New Issue
Block a user