get rid of separate sign/self-encrypt key ids in message builder
This commit is contained in:
parent
5b6d74e80a
commit
01c5493ca1
4 changed files with 27 additions and 30 deletions
|
@ -22,16 +22,15 @@ public class ComposeCryptoStatus {
|
|||
|
||||
|
||||
private CryptoProviderState cryptoProviderState;
|
||||
private Long signingKeyId;
|
||||
private Long selfEncryptKeyId;
|
||||
private Long openPgpKeyId;
|
||||
private String[] recipientAddresses;
|
||||
private boolean enablePgpInline;
|
||||
private CryptoMode cryptoMode;
|
||||
private RecipientAutocryptStatus recipientAutocryptStatus;
|
||||
|
||||
|
||||
public Long getSigningKeyId() {
|
||||
return signingKeyId;
|
||||
public Long getOpenPgpKeyId() {
|
||||
return openPgpKeyId;
|
||||
}
|
||||
|
||||
CryptoStatusDisplayType getCryptoStatusDisplayType() {
|
||||
|
@ -187,8 +186,7 @@ public class ComposeCryptoStatus {
|
|||
|
||||
private CryptoProviderState cryptoProviderState;
|
||||
private CryptoMode cryptoMode;
|
||||
private Long signingKeyId;
|
||||
private Long selfEncryptKeyId;
|
||||
private Long openPgpKeyId;
|
||||
private List<Recipient> recipients;
|
||||
private Boolean enablePgpInline;
|
||||
|
||||
|
@ -202,13 +200,8 @@ public class ComposeCryptoStatus {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ComposeCryptoStatusBuilder setSigningKeyId(Long signingKeyId) {
|
||||
this.signingKeyId = signingKeyId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ComposeCryptoStatusBuilder setSelfEncryptId(Long selfEncryptKeyId) {
|
||||
this.selfEncryptKeyId = selfEncryptKeyId;
|
||||
public ComposeCryptoStatusBuilder setOpenPgpKeyId(Long openPgpKeyId) {
|
||||
this.openPgpKeyId = openPgpKeyId;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -245,8 +238,7 @@ public class ComposeCryptoStatus {
|
|||
result.cryptoProviderState = cryptoProviderState;
|
||||
result.cryptoMode = cryptoMode;
|
||||
result.recipientAddresses = recipientAddresses.toArray(new String[0]);
|
||||
result.signingKeyId = signingKeyId;
|
||||
result.selfEncryptKeyId = selfEncryptKeyId;
|
||||
result.openPgpKeyId = openPgpKeyId;
|
||||
result.enablePgpInline = enablePgpInline;
|
||||
return result;
|
||||
}
|
||||
|
@ -257,8 +249,7 @@ public class ComposeCryptoStatus {
|
|||
result.cryptoProviderState = cryptoProviderState;
|
||||
result.cryptoMode = cryptoMode;
|
||||
result.recipientAddresses = recipientAddresses;
|
||||
result.signingKeyId = signingKeyId;
|
||||
result.selfEncryptKeyId = selfEncryptKeyId;
|
||||
result.openPgpKeyId = openPgpKeyId;
|
||||
result.enablePgpInline = enablePgpInline;
|
||||
result.recipientAutocryptStatus = recipientAutocryptStatusType;
|
||||
return result;
|
||||
|
|
|
@ -400,8 +400,7 @@ public class RecipientPresenter implements PermissionPingCallback {
|
|||
.setCryptoMode(currentCryptoMode)
|
||||
.setEnablePgpInline(cryptoEnablePgpInline)
|
||||
.setRecipients(getAllRecipients())
|
||||
.setSigningKeyId(accountCryptoKey)
|
||||
.setSelfEncryptId(accountCryptoKey)
|
||||
.setOpenPgpKeyId(accountCryptoKey)
|
||||
.build();
|
||||
|
||||
final String[] recipientAddresses = composeCryptoStatus.getRecipientAddresses();
|
||||
|
|
|
@ -135,6 +135,8 @@ public class PgpMessageBuilder extends MessageBuilder {
|
|||
@NonNull
|
||||
private Intent buildOpenPgpApiIntent(boolean shouldSign, boolean shouldEncrypt, boolean isPgpInlineMode) {
|
||||
Intent pgpApiIntent;
|
||||
|
||||
Long openPgpKeyId = cryptoStatus.getOpenPgpKeyId();
|
||||
if (shouldEncrypt) {
|
||||
if (!shouldSign) {
|
||||
throw new IllegalStateException("encrypt-only is not supported at this point and should never happen!");
|
||||
|
@ -142,6 +144,11 @@ public class PgpMessageBuilder extends MessageBuilder {
|
|||
// pgpApiIntent = new Intent(shouldSign ? OpenPgpApi.ACTION_SIGN_AND_ENCRYPT : OpenPgpApi.ACTION_ENCRYPT);
|
||||
pgpApiIntent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
|
||||
|
||||
if (openPgpKeyId != null) {
|
||||
long[] selfEncryptIds = { openPgpKeyId };
|
||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, selfEncryptIds);
|
||||
}
|
||||
|
||||
if(!isDraft()) {
|
||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
|
||||
// pgpApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, cryptoStatus.isEncryptionOpportunistic());
|
||||
|
@ -151,7 +158,7 @@ public class PgpMessageBuilder extends MessageBuilder {
|
|||
}
|
||||
|
||||
if (shouldSign) {
|
||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, cryptoStatus.getSigningKeyId());
|
||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, openPgpKeyId);
|
||||
}
|
||||
|
||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||
|
|
|
@ -62,8 +62,7 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
@RunWith(K9RobolectricTestRunner.class)
|
||||
public class PgpMessageBuilderTest {
|
||||
private static final long TEST_SIGN_KEY_ID = 123L;
|
||||
private static final long TEST_SELF_ENCRYPT_KEY_ID = 234L;
|
||||
private static final long TEST_KEY_ID = 123L;
|
||||
private static final String TEST_MESSAGE_TEXT = "message text with a ☭ CCCP symbol";
|
||||
|
||||
|
||||
|
@ -126,7 +125,7 @@ public class PgpMessageBuilderTest {
|
|||
pgpMessageBuilder.buildAsync(mockCallback);
|
||||
|
||||
Intent expectedIntent = new Intent(OpenPgpApi.ACTION_DETACHED_SIGN);
|
||||
expectedIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID);
|
||||
expectedIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_KEY_ID);
|
||||
expectedIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||
assertIntentEqualsActionAndExtras(expectedIntent, capturedApiIntent.getValue());
|
||||
|
||||
|
@ -267,7 +266,8 @@ public class PgpMessageBuilderTest {
|
|||
pgpMessageBuilder.buildAsync(mockCallback);
|
||||
|
||||
Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID);
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_KEY_ID);
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[] { TEST_KEY_ID });
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
|
||||
assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue());
|
||||
|
@ -318,7 +318,8 @@ public class PgpMessageBuilderTest {
|
|||
pgpMessageBuilder.buildAsync(mockCallback);
|
||||
|
||||
Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID);
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_KEY_ID);
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[] { TEST_KEY_ID });
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
|
||||
assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue());
|
||||
|
@ -354,7 +355,7 @@ public class PgpMessageBuilderTest {
|
|||
pgpMessageBuilder.buildAsync(mockCallback);
|
||||
|
||||
Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN);
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID);
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_KEY_ID);
|
||||
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||
assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue());
|
||||
|
||||
|
@ -455,8 +456,7 @@ public class PgpMessageBuilderTest {
|
|||
private ComposeCryptoStatusBuilder createDefaultComposeCryptoStatusBuilder() {
|
||||
return new ComposeCryptoStatusBuilder()
|
||||
.setEnablePgpInline(false)
|
||||
.setSigningKeyId(TEST_SIGN_KEY_ID)
|
||||
.setSelfEncryptId(TEST_SELF_ENCRYPT_KEY_ID)
|
||||
.setOpenPgpKeyId(TEST_KEY_ID)
|
||||
.setRecipients(new ArrayList<Recipient>())
|
||||
.setCryptoProviderState(CryptoProviderState.OK);
|
||||
}
|
||||
|
@ -543,11 +543,11 @@ public class PgpMessageBuilderTest {
|
|||
}
|
||||
if (intentExtra instanceof long[]) {
|
||||
if (!Arrays.equals((long[]) intentExtra, (long[]) expectedExtra)) {
|
||||
Assert.assertArrayEquals((long[]) expectedExtra, (long[]) intentExtra);
|
||||
Assert.assertArrayEquals("error in " + key, (long[]) expectedExtra, (long[]) intentExtra);
|
||||
}
|
||||
} else {
|
||||
if (!intentExtra.equals(expectedExtra)) {
|
||||
Assert.assertEquals(expectedExtra, intentExtra);
|
||||
Assert.assertEquals("error in " + key, expectedExtra, intentExtra);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue