Merge pull request #2783 from k9mail/autocrypt-mutual

don't default to prefer-encrypt mutual
This commit is contained in:
Vincent Breitmoser 2017-10-06 01:04:28 +02:00 committed by GitHub
commit d4eb23894d
3 changed files with 15 additions and 2 deletions

View file

@ -25,6 +25,7 @@ public class ComposeCryptoStatus {
private Long openPgpKeyId; private Long openPgpKeyId;
private String[] recipientAddresses; private String[] recipientAddresses;
private boolean enablePgpInline; private boolean enablePgpInline;
private boolean preferEncryptMutual;
private CryptoMode cryptoMode; private CryptoMode cryptoMode;
private RecipientAutocryptStatus recipientAutocryptStatus; private RecipientAutocryptStatus recipientAutocryptStatus;
@ -83,7 +84,7 @@ public class ComposeCryptoStatus {
case NO_CHOICE: case NO_CHOICE:
if (recipientAutocryptStatusType == RecipientAutocryptStatusType.NO_RECIPIENTS) { if (recipientAutocryptStatusType == RecipientAutocryptStatusType.NO_RECIPIENTS) {
return CryptoStatusDisplayType.NO_CHOICE_EMPTY; return CryptoStatusDisplayType.NO_CHOICE_EMPTY;
} else if (recipientAutocryptStatusType.canEncrypt() && recipientAutocryptStatusType.isMutual()) { // TODO check own "mutual" status } else if (canEncryptAndIsMutual()) {
if (recipientAutocryptStatusType.isConfirmed()) { if (recipientAutocryptStatusType.isConfirmed()) {
return CryptoStatusDisplayType.NO_CHOICE_MUTUAL_TRUSTED; return CryptoStatusDisplayType.NO_CHOICE_MUTUAL_TRUSTED;
} else { } else {
@ -168,7 +169,7 @@ public class ComposeCryptoStatus {
} }
boolean canEncryptAndIsMutual() { boolean canEncryptAndIsMutual() {
return allRecipientsCanEncrypt() && recipientAutocryptStatus.type.isMutual(); return allRecipientsCanEncrypt() && preferEncryptMutual && recipientAutocryptStatus.type.isMutual();
} }
boolean hasAutocryptPendingIntent() { boolean hasAutocryptPendingIntent() {
@ -186,6 +187,7 @@ public class ComposeCryptoStatus {
private Long openPgpKeyId; private Long openPgpKeyId;
private List<Recipient> recipients; private List<Recipient> recipients;
private Boolean enablePgpInline; private Boolean enablePgpInline;
private Boolean preferEncryptMutual;
public ComposeCryptoStatusBuilder setCryptoProviderState(CryptoProviderState cryptoProviderState) { public ComposeCryptoStatusBuilder setCryptoProviderState(CryptoProviderState cryptoProviderState) {
this.cryptoProviderState = cryptoProviderState; this.cryptoProviderState = cryptoProviderState;
@ -212,6 +214,11 @@ public class ComposeCryptoStatus {
return this; return this;
} }
public ComposeCryptoStatusBuilder setPreferEncryptMutual(boolean preferEncryptMutual) {
this.preferEncryptMutual = preferEncryptMutual;
return this;
}
public ComposeCryptoStatus build() { public ComposeCryptoStatus build() {
if (cryptoProviderState == null) { if (cryptoProviderState == null) {
throw new AssertionError("cryptoProviderState must be set!"); throw new AssertionError("cryptoProviderState must be set!");
@ -225,6 +232,9 @@ public class ComposeCryptoStatus {
if (enablePgpInline == null) { if (enablePgpInline == null) {
throw new AssertionError("enablePgpInline must be set!"); throw new AssertionError("enablePgpInline must be set!");
} }
if (preferEncryptMutual == null) {
throw new AssertionError("preferEncryptMutual must be set!");
}
ArrayList<String> recipientAddresses = new ArrayList<>(); ArrayList<String> recipientAddresses = new ArrayList<>();
for (Recipient recipient : recipients) { for (Recipient recipient : recipients) {
@ -237,6 +247,7 @@ public class ComposeCryptoStatus {
result.recipientAddresses = recipientAddresses.toArray(new String[0]); result.recipientAddresses = recipientAddresses.toArray(new String[0]);
result.openPgpKeyId = openPgpKeyId; result.openPgpKeyId = openPgpKeyId;
result.enablePgpInline = enablePgpInline; result.enablePgpInline = enablePgpInline;
result.preferEncryptMutual = preferEncryptMutual;
return result; return result;
} }
} }

View file

@ -400,6 +400,7 @@ public class RecipientPresenter implements PermissionPingCallback {
.setCryptoProviderState(cryptoProviderState) .setCryptoProviderState(cryptoProviderState)
.setCryptoMode(currentCryptoMode) .setCryptoMode(currentCryptoMode)
.setEnablePgpInline(cryptoEnablePgpInline) .setEnablePgpInline(cryptoEnablePgpInline)
.setPreferEncryptMutual(false) // TODO introduce a setting
.setRecipients(getAllRecipients()) .setRecipients(getAllRecipients())
.setOpenPgpKeyId(accountCryptoKey) .setOpenPgpKeyId(accountCryptoKey)
.build(); .build();

View file

@ -546,6 +546,7 @@ public class PgpMessageBuilderTest {
private ComposeCryptoStatusBuilder createDefaultComposeCryptoStatusBuilder() { private ComposeCryptoStatusBuilder createDefaultComposeCryptoStatusBuilder() {
return new ComposeCryptoStatusBuilder() return new ComposeCryptoStatusBuilder()
.setEnablePgpInline(false) .setEnablePgpInline(false)
.setPreferEncryptMutual(false)
.setOpenPgpKeyId(TEST_KEY_ID) .setOpenPgpKeyId(TEST_KEY_ID)
.setRecipients(new ArrayList<Recipient>()) .setRecipients(new ArrayList<Recipient>())
.setCryptoProviderState(CryptoProviderState.OK); .setCryptoProviderState(CryptoProviderState.OK);