compose: extract putEncryptionIntentExtras method in PgpMessageBuilder
This commit is contained in:
parent
fe4429416a
commit
029b04a1db
1 changed files with 19 additions and 33 deletions
|
@ -167,23 +167,7 @@ public class PgpMessageBuilder extends MessageBuilder {
|
||||||
Intent pgpApiIntent;
|
Intent pgpApiIntent;
|
||||||
if (shouldEncrypt) {
|
if (shouldEncrypt) {
|
||||||
pgpApiIntent = new Intent(OpenPgpApi.ACTION_ENCRYPT);
|
pgpApiIntent = new Intent(OpenPgpApi.ACTION_ENCRYPT);
|
||||||
|
putEncryptionIntentExtras(pgpApiIntent);
|
||||||
long[] encryptKeyIds = cryptoStatus.getEncryptKeyIds();
|
|
||||||
if (encryptKeyIds != null) {
|
|
||||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, encryptKeyIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isDraft()) {
|
|
||||||
String[] encryptRecipientAddresses = cryptoStatus.getRecipientAddresses();
|
|
||||||
boolean hasRecipientAddresses = encryptRecipientAddresses != null && encryptRecipientAddresses.length > 0;
|
|
||||||
if (!hasRecipientAddresses) {
|
|
||||||
// TODO safeguard here once this is better handled by the caller?
|
|
||||||
// throw new MessagingException("Encryption is enabled, but no encryption key specified!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, encryptRecipientAddresses);
|
|
||||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, cryptoStatus.isEncryptionOpportunistic());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
pgpApiIntent = new Intent(OpenPgpApi.ACTION_SIGN);
|
pgpApiIntent = new Intent(OpenPgpApi.ACTION_SIGN);
|
||||||
}
|
}
|
||||||
|
@ -212,22 +196,7 @@ public class PgpMessageBuilder extends MessageBuilder {
|
||||||
Intent encryptIntent = new Intent(OpenPgpApi.ACTION_ENCRYPT);
|
Intent encryptIntent = new Intent(OpenPgpApi.ACTION_ENCRYPT);
|
||||||
encryptIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
encryptIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||||
|
|
||||||
long[] encryptKeyIds = cryptoStatus.getEncryptKeyIds();
|
putEncryptionIntentExtras(encryptIntent);
|
||||||
if (encryptKeyIds != null) {
|
|
||||||
encryptIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, encryptKeyIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isDraft()) {
|
|
||||||
String[] encryptRecipientAddresses = cryptoStatus.getRecipientAddresses();
|
|
||||||
boolean hasRecipientAddresses = encryptRecipientAddresses != null && encryptRecipientAddresses.length > 0;
|
|
||||||
if (!hasRecipientAddresses) {
|
|
||||||
// TODO safeguard here once this is better handled by the caller?
|
|
||||||
// throw new MessagingException("Encryption is enabled, but no encryption key specified!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
encryptIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, encryptRecipientAddresses);
|
|
||||||
encryptIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, cryptoStatus.isEncryptionOpportunistic());
|
|
||||||
}
|
|
||||||
|
|
||||||
currentState = State.OPENPGP_ENCRYPT;
|
currentState = State.OPENPGP_ENCRYPT;
|
||||||
mimeIntentLaunch(encryptIntent);
|
mimeIntentLaunch(encryptIntent);
|
||||||
|
@ -254,6 +223,23 @@ public class PgpMessageBuilder extends MessageBuilder {
|
||||||
mimeIntentLaunch(signIntent);
|
mimeIntentLaunch(signIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void putEncryptionIntentExtras(Intent pgpApiIntent) throws MessagingException {
|
||||||
|
long[] encryptKeyIds = cryptoStatus.getEncryptKeyIds();
|
||||||
|
if (encryptKeyIds != null) {
|
||||||
|
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, encryptKeyIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isDraft()) {
|
||||||
|
String[] encryptRecipientAddresses = cryptoStatus.getRecipientAddresses();
|
||||||
|
boolean hasRecipientAddresses = encryptRecipientAddresses != null && encryptRecipientAddresses.length > 0;
|
||||||
|
if (!hasRecipientAddresses) {
|
||||||
|
throw new MessagingException("Encryption is enabled, but no encryption key specified!");
|
||||||
|
}
|
||||||
|
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, encryptRecipientAddresses);
|
||||||
|
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, cryptoStatus.isEncryptionOpportunistic());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** This method executes the given Intent with the OpenPGP Api. It will pass the
|
/** This method executes the given Intent with the OpenPGP Api. It will pass the
|
||||||
* entire current message as input. On success, either mimeBuildSignedMessage() or
|
* entire current message as input. On success, either mimeBuildSignedMessage() or
|
||||||
* mimeBuildEncryptedMessage() will be called with their appropriate inputs. If an
|
* mimeBuildEncryptedMessage() will be called with their appropriate inputs. If an
|
||||||
|
|
Loading…
Reference in a new issue