add "external" state for keys from non-autocrypt inputs

This commit is contained in:
Vincent Breitmoser
2017-06-26 22:48:41 +02:00
parent 3212da0915
commit 33555c6f20
2 changed files with 26 additions and 4 deletions

View File

@@ -309,12 +309,30 @@ public class OpenPgpService extends Service {
AutocryptState combinedAutocryptState = keyIdResult.getCombinedAutocryptState(); AutocryptState combinedAutocryptState = keyIdResult.getCombinedAutocryptState();
if (combinedAutocryptState == null) { if (combinedAutocryptState == null) {
result.putExtra(OpenPgpApi.RESULT_AUTOCRYPT_STATUS, OpenPgpApi.AUTOCRYPT_STATUS_UNAVAILABLE); switch (keyIdResult.getStatus()) {
case NO_KEYS:
case NO_KEYS_ERROR:
case MISSING: {
result.putExtra(OpenPgpApi.RESULT_AUTOCRYPT_STATUS, OpenPgpApi.AUTOCRYPT_STATUS_UNAVAILABLE);
break;
}
case DUPLICATE: {
if (keyIdResult.hasKeySelectionPendingIntent()) {
result.putExtra(OpenPgpApi.RESULT_INTENT, keyIdResult.getKeySelectionPendingIntent());
}
result.putExtra(OpenPgpApi.RESULT_AUTOCRYPT_STATUS, OpenPgpApi.AUTOCRYPT_STATUS_DISCOURAGE);
break;
}
case OK: {
result.putExtra(OpenPgpApi.RESULT_AUTOCRYPT_STATUS, OpenPgpApi.AUTOCRYPT_STATUS_DISCOURAGE);
break;
}
}
return result; return result;
} }
switch (combinedAutocryptState) { switch (combinedAutocryptState) {
case EXTERNAL:
case GOSSIP: case GOSSIP:
case RESET: { case RESET: {
result.putExtra(OpenPgpApi.RESULT_AUTOCRYPT_STATUS, OpenPgpApi.AUTOCRYPT_STATUS_DISCOURAGE); result.putExtra(OpenPgpApi.RESULT_AUTOCRYPT_STATUS, OpenPgpApi.AUTOCRYPT_STATUS_DISCOURAGE);
@@ -325,7 +343,7 @@ public class OpenPgpService extends Service {
break; break;
} }
case MUTUAL: { case MUTUAL: {
result.putExtra(OpenPgpApi.RESULT_AUTOCRYPT_STATUS, OpenPgpApi.AUTOCRYPT_STATUS_RECOMMEND); result.putExtra(OpenPgpApi.RESULT_AUTOCRYPT_STATUS, OpenPgpApi.AUTOCRYPT_STATUS_MUTUAL);
break; break;
} }
default: { default: {

View File

@@ -123,6 +123,7 @@ class OpenPgpServiceKeyIdExtractor {
if (addressQueryResult.uidMasterKeyId != null) { if (addressQueryResult.uidMasterKeyId != null) {
keyIds.add(addressQueryResult.uidMasterKeyId); keyIds.add(addressQueryResult.uidMasterKeyId);
combinedAutocryptState = AutocryptState.EXTERNAL;
if (addressQueryResult.uidHasMultipleCandidates) { if (addressQueryResult.uidHasMultipleCandidates) {
duplicateEmails.add(queriedAddress); duplicateEmails.add(queriedAddress);
@@ -219,7 +220,7 @@ class OpenPgpServiceKeyIdExtractor {
} }
enum AutocryptState { enum AutocryptState {
RESET, GOSSIP, AVAILABLE, MUTUAL; EXTERNAL, RESET, GOSSIP, AVAILABLE, MUTUAL;
static AutocryptState fromDbValue(int state) { static AutocryptState fromDbValue(int state) {
switch (state) { switch (state) {
@@ -237,6 +238,9 @@ class OpenPgpServiceKeyIdExtractor {
} }
public AutocryptState combineWith(AutocryptState other) { public AutocryptState combineWith(AutocryptState other) {
if (this == EXTERNAL || other == EXTERNAL) {
return EXTERNAL;
}
if (this == RESET || other == RESET) { if (this == RESET || other == RESET) {
return RESET; return RESET;
} }