catch null pointer exceptions when the private key cannot be extracted, also prevent such keys from getting imported, so the error message should never be encountered anyway

Fixes issue 66
This commit is contained in:
Thialfihar
2010-09-10 20:36:38 +00:00
parent c4489dc31e
commit bc50ca0093
5 changed files with 62 additions and 6 deletions

View File

@@ -18,7 +18,9 @@ package org.thialfihar.android.apg;
import org.bouncycastle2.jce.provider.BouncyCastleProvider;
import org.bouncycastle2.openpgp.PGPException;
import org.bouncycastle2.openpgp.PGPPrivateKey;
import org.bouncycastle2.openpgp.PGPSecretKey;
import org.thialfihar.android.apg.Apg.GeneralException;
import android.app.Activity;
import android.app.AlertDialog;
@@ -84,8 +86,14 @@ public class AskForSecretKeyPassPhrase {
long keyId;
if (secretKey != null) {
try {
secretKey.extractPrivateKey(passPhrase.toCharArray(),
new BouncyCastleProvider());
PGPPrivateKey testKey = secretKey.extractPrivateKey(passPhrase.toCharArray(),
new BouncyCastleProvider());
if (testKey == null) {
Toast.makeText(activity,
R.string.error_couldNotExtractPrivateKey,
Toast.LENGTH_SHORT).show();
return;
}
} catch (PGPException e) {
Toast.makeText(activity,
R.string.wrongPassPhrase,