internal renaming, cleanup

This commit is contained in:
Dominik Schürmann 2014-02-21 02:40:44 +01:00
parent aaddd26b51
commit fb0816c126
5 changed files with 50 additions and 36 deletions

View File

@ -70,7 +70,7 @@ import java.util.Iterator;
/**
* This class uses a Builder pattern!
*/
public class PgpOperationIncoming {
public class PgpDecryptVerify {
private Context context;
private InputData data;
private OutputStream outStream;
@ -79,7 +79,7 @@ public class PgpOperationIncoming {
boolean assumeSymmetric;
String passphrase;
private PgpOperationIncoming(Builder builder) {
private PgpDecryptVerify(Builder builder) {
// private Constructor can only be called from Builder
this.context = builder.context;
this.data = builder.data;
@ -122,8 +122,8 @@ public class PgpOperationIncoming {
return this;
}
public PgpOperationIncoming build() {
return new PgpOperationIncoming(this);
public PgpDecryptVerify build() {
return new PgpDecryptVerify(this);
}
}
@ -177,9 +177,8 @@ public class PgpOperationIncoming {
* @throws PGPException
* @throws SignatureException
*/
public Bundle decryptVerify()
public Bundle execute()
throws IOException, PgpGeneralException, PGPException, SignatureException {
Bundle returnData = new Bundle();
// automatically works with ascii armor input and binary
InputStream in = PGPUtil.getDecoderStream(data.getInputStream());
@ -191,14 +190,30 @@ public class PgpOperationIncoming {
if (aIn.isClearText()) {
// a cleartext signature, verify it with the other method
return verifyCleartextSignature(aIn);
} else {
// go on...
}
// else: ascii armored encryption! go on...
}
return decryptVerify(in);
}
/**
* Decrypt and/or verifies binary or ascii armored pgp
*
* @param in
* @return
* @throws IOException
* @throws PgpGeneralException
* @throws PGPException
* @throws SignatureException
*/
private Bundle decryptVerify(InputStream in)
throws IOException, PgpGeneralException, PGPException, SignatureException {
Bundle returnData = new Bundle();
PGPObjectFactory pgpF = new PGPObjectFactory(in);
PGPEncryptedDataList enc;
Object o = pgpF.nextObject();
Log.d(Constants.TAG, "o: " + o.getClass().getName());
int currentProgress = 0;
updateProgress(R.string.progress_reading_data, currentProgress, 100);

View File

@ -62,7 +62,7 @@ import java.util.Date;
/**
* This class uses a Builder pattern!
*/
public class PgpOperationOutgoing {
public class PgpSignEncrypt {
private Context context;
private InputData data;
private OutputStream outStream;
@ -78,7 +78,7 @@ public class PgpOperationOutgoing {
private boolean signatureForceV3;
private String signaturePassphrase;
private PgpOperationOutgoing(Builder builder) {
private PgpSignEncrypt(Builder builder) {
// private Constructor can only be called from Builder
this.context = builder.context;
this.data = builder.data;
@ -170,8 +170,8 @@ public class PgpOperationOutgoing {
return this;
}
public PgpOperationOutgoing build() {
return new PgpOperationOutgoing(this);
public PgpSignEncrypt build() {
return new PgpSignEncrypt(this);
}
}
@ -197,7 +197,7 @@ public class PgpOperationOutgoing {
* @throws NoSuchAlgorithmException
* @throws SignatureException
*/
public void signEncrypt()
public void execute()
throws IOException, PgpGeneralException, PGPException, NoSuchProviderException,
NoSuchAlgorithmException, SignatureException {
@ -442,7 +442,7 @@ public class PgpOperationOutgoing {
updateProgress(R.string.progress_done, 100, 100);
}
// TODO: merge this into signEncrypt method!
// TODO: merge this into execute method!
// TODO: allow binary input for this class
public void generateSignature()
throws PgpGeneralException, PGPException, IOException, NoSuchAlgorithmException,

View File

@ -43,11 +43,11 @@ import org.sufficientlysecure.keychain.helper.FileHelper;
import org.sufficientlysecure.keychain.helper.OtherHelper;
import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpImportExport;
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.PgpOperationIncoming;
import org.sufficientlysecure.keychain.pgp.PgpOperationOutgoing;
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract.DataStream;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
@ -317,8 +317,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
}
/* Operation */
PgpOperationOutgoing.Builder builder =
new PgpOperationOutgoing.Builder(this, inputData, outStream);
PgpSignEncrypt.Builder builder =
new PgpSignEncrypt.Builder(this, inputData, outStream);
builder.progress(this);
if (generateSignature) {
@ -338,7 +338,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
.signatureHashAlgorithm(Preferences.getPreferences(this).getDefaultHashAlgorithm())
.signaturePassphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId));
builder.build().signEncrypt();
builder.build().execute();
} else {
Log.d(Constants.TAG, "encrypt...");
builder.enableAsciiArmorOutput(useAsciiArmor)
@ -351,7 +351,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
.signatureHashAlgorithm(Preferences.getPreferences(this).getDefaultHashAlgorithm())
.signaturePassphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId));
builder.build().signEncrypt();
builder.build().execute();
}
outStream.close();
@ -480,13 +480,13 @@ public class KeychainIntentService extends IntentService implements ProgressDial
// verifyText and decrypt returning additional resultData values for the
// verification of signatures
PgpOperationIncoming.Builder builder = new PgpOperationIncoming.Builder(this, inputData, outStream);
PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder(this, inputData, outStream);
builder.progress(this);
builder.assumeSymmetric(assumeSymmetricEncryption)
.passphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId));
resultData = builder.build().decryptVerify();
resultData = builder.build().execute();
outStream.close();

View File

@ -32,8 +32,8 @@ import org.openintents.openpgp.util.OpenPgpConstants;
import org.spongycastle.util.Arrays;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.pgp.PgpOperationOutgoing;
import org.sufficientlysecure.keychain.pgp.PgpOperationIncoming;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
@ -162,13 +162,13 @@ public class OpenPgpService extends RemoteService {
InputData inputData = new InputData(is, inputLength);
// sign-only
PgpOperationOutgoing.Builder builder = new PgpOperationOutgoing.Builder(getContext(), inputData, os);
PgpSignEncrypt.Builder builder = new PgpSignEncrypt.Builder(getContext(), inputData, os);
builder.enableAsciiArmorOutput(asciiArmor)
.signatureHashAlgorithm(appSettings.getHashAlgorithm())
.signatureForceV3(false)
.signatureKeyId(appSettings.getKeyId())
.signaturePassphrase(passphrase);
builder.build().signEncrypt();
builder.build().execute();
} finally {
is.close();
os.close();
@ -227,7 +227,7 @@ public class OpenPgpService extends RemoteService {
long inputLength = is.available();
InputData inputData = new InputData(is, inputLength);
PgpOperationOutgoing.Builder builder = new PgpOperationOutgoing.Builder(getContext(), inputData, os);
PgpSignEncrypt.Builder builder = new PgpSignEncrypt.Builder(getContext(), inputData, os);
builder.enableAsciiArmorOutput(asciiArmor)
.compressionId(appSettings.getCompression())
.symmetricEncryptionAlgorithm(appSettings.getEncryptionAlgorithm())
@ -257,7 +257,7 @@ public class OpenPgpService extends RemoteService {
builder.signatureKeyId(Id.key.none);
}
// execute PGP operation!
builder.build().signEncrypt();
builder.build().execute();
} finally {
is.close();
os.close();
@ -354,7 +354,7 @@ public class OpenPgpService extends RemoteService {
// inputStream2.reset();
// }
// secretKeyId = Id.key.symmetric;
// if (!PgpOperationIncoming.hasSymmetricEncryption(this, inputStream2)) {
// if (!PgpDecryptVerify.hasSymmetricEncryption(this, inputStream2)) {
// throw new PgpGeneralException(
// getString(R.string.error_no_known_encryption_found));
// }
@ -384,7 +384,7 @@ public class OpenPgpService extends RemoteService {
Bundle outputBundle;
PgpOperationIncoming.Builder builder = new PgpOperationIncoming.Builder(this, inputData, os);
PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder(this, inputData, os);
// if (signedOnly) {
// outputBundle = builder.build().verifyText();
@ -396,7 +396,7 @@ public class OpenPgpService extends RemoteService {
// pause stream when passphrase is missing and then resume???
// TODO: this also decrypts with other secret keys without passphrase!!!
outputBundle = builder.build().decryptVerify();
outputBundle = builder.build().execute();
// }
// outputStream.close();
@ -425,7 +425,6 @@ public class OpenPgpService extends RemoteService {
signatureStatus = OpenPgpSignatureResult.SIGNATURE_UNKNOWN_PUB_KEY;
}
// TODO: signed only?!?!?!
sigResult = new OpenPgpSignatureResult(signatureStatus, signatureUserId,
signatureOnly, signatureKeyId);
}

View File

@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.helper.ActionBarHelper;
import org.sufficientlysecure.keychain.helper.FileHelper;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.PgpOperationIncoming;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.exception.NoAsymmetricEncryptionException;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
@ -85,7 +85,7 @@ public class DecryptActivity extends DrawerActivity {
private boolean mReturnResult = false;
// TODO: replace signed only checks with something more intelligent
// PgpOperationIncoming should handle all automatically!!!
// PgpDecryptVerify should handle all automatically!!!
private boolean mSignedOnly = false;
private boolean mAssumeSymmetricEncryption = false;
@ -549,7 +549,7 @@ public class DecryptActivity extends DrawerActivity {
inStream.reset();
}
mSecretKeyId = Id.key.symmetric;
if (!PgpOperationIncoming.hasSymmetricEncryption(this, inStream)) {
if (!PgpDecryptVerify.hasSymmetricEncryption(this, inStream)) {
throw new PgpGeneralException(
getString(R.string.error_no_known_encryption_found));
}