service: support EXTRA_DRY_RUN to get key status for a sign/encrypt run

This commit is contained in:
Vincent Breitmoser 2017-02-28 19:06:00 +01:00
parent 2a26908fb6
commit 612cd89046
2 changed files with 42 additions and 2 deletions

View file

@ -116,7 +116,7 @@ public class OpenPgpService extends Service {
Intent signKeyIdIntent = getSignKeyMasterId(data);
// NOTE: Fallback to return account settings (Old API)
if (signKeyIdIntent.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)
if (signKeyIdIntent.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS)
== OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED) {
return signKeyIdIntent;
}
@ -237,8 +237,12 @@ public class OpenPgpService extends Service {
KeyIdResult keyIdResult = mKeyIdExtractor.returnKeyIdsFromIntent(data, false,
mApiPermissionHelper.getCurrentCallingPackage());
boolean isDryRun = data.getBooleanExtra(OpenPgpApi.EXTRA_DRY_RUN, false);
boolean isOpportunistic = data.getBooleanExtra(OpenPgpApi.EXTRA_OPPORTUNISTIC_ENCRYPTION, false);
KeyIdResultStatus keyIdResultStatus = keyIdResult.getStatus();
if (isDryRun) {
return getDryRunStatusResult(keyIdResult);
}
if (keyIdResult.hasKeySelectionPendingIntent()) {
if ((keyIdResultStatus == KeyIdResultStatus.MISSING || keyIdResultStatus == KeyIdResultStatus.NO_KEYS ||
@ -298,6 +302,42 @@ public class OpenPgpService extends Service {
}
}
@NonNull
private Intent getDryRunStatusResult(KeyIdResult keyIdResult) {
switch (keyIdResult.getStatus()) {
case MISSING: {
Intent result = new Intent();
result.putExtra(OpenPgpApi.RESULT_ERROR,
new OpenPgpError(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS, "missing keys in opportunistic mode"));
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
return result;
}
case NO_KEYS:
case NO_KEYS_ERROR: {
Intent result = new Intent();
result.putExtra(OpenPgpApi.RESULT_ERROR,
new OpenPgpError(OpenPgpError.NO_USER_IDS, "empty recipient list"));
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
return result;
}
case DUPLICATE: {
Intent result = new Intent();
result.putExtra(OpenPgpApi.RESULT_KEYS_CONFIRMED, false);
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
return result;
}
case OK: {
Intent result = new Intent();
result.putExtra(OpenPgpApi.RESULT_KEYS_CONFIRMED, keyIdResult.isAllKeysConfirmed());
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
return result;
}
default: {
throw new IllegalStateException("unhandled case!");
}
}
}
private Intent decryptAndVerifyImpl(Intent data, InputStream inputStream, OutputStream outputStream,
boolean decryptMetadataOnly, Progressable progressable) {
try {

@ -1 +1 @@
Subproject commit 5aa2affb752c066232bd7e7bb7c22739fa9f3526
Subproject commit f28cb92944efbf56fa0582769a97b23c4272f6ac