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