added file decryption, rewrote the various "Choice" derivations to us the Id structure as well
This commit is contained in:
@@ -24,7 +24,9 @@ import java.util.Vector;
|
||||
|
||||
import org.bouncycastle2.openpgp.PGPSecretKey;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.R.id;
|
||||
import org.thialfihar.android.apg.utils.Choice;
|
||||
|
||||
import android.app.DatePickerDialog;
|
||||
@@ -65,26 +67,6 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
}
|
||||
};
|
||||
|
||||
public static class AlgorithmChoice extends Choice {
|
||||
public static final int DSA = 1;
|
||||
public static final int ELGAMAL = 2;
|
||||
public static final int RSA = 3;
|
||||
|
||||
public AlgorithmChoice(int id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UsageChoice extends Choice {
|
||||
public static final int SIGN_ONLY = 1;
|
||||
public static final int ENCRYPT_ONLY = 2;
|
||||
public static final int SIGN_AND_ENCRYPT = 3;
|
||||
|
||||
public UsageChoice(int id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
}
|
||||
|
||||
public KeyEditor(Context context) {
|
||||
super(context);
|
||||
}
|
||||
@@ -103,18 +85,17 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
mCreationDate = (TextView) findViewById(R.id.creation);
|
||||
mExpiryDateButton = (Button) findViewById(R.id.expiry);
|
||||
mUsage = (Spinner) findViewById(R.id.usage);
|
||||
KeyEditor.UsageChoice choices[] = {
|
||||
new KeyEditor.UsageChoice(KeyEditor.UsageChoice.SIGN_ONLY,
|
||||
getResources().getString(R.string.sign_only)),
|
||||
new KeyEditor.UsageChoice(KeyEditor.UsageChoice.ENCRYPT_ONLY,
|
||||
getResources().getString(R.string.encrypt_only)),
|
||||
new KeyEditor.UsageChoice(KeyEditor.UsageChoice.SIGN_AND_ENCRYPT,
|
||||
getResources().getString(R.string.sign_and_encrypt)),
|
||||
Choice choices[] = {
|
||||
new Choice(Id.choice.usage.sign_only,
|
||||
getResources().getString(R.string.sign_only)),
|
||||
new Choice(Id.choice.usage.encrypt_only,
|
||||
getResources().getString(R.string.encrypt_only)),
|
||||
new Choice(Id.choice.usage.sign_and_encrypt,
|
||||
getResources().getString(R.string.sign_and_encrypt)),
|
||||
};
|
||||
ArrayAdapter<KeyEditor.UsageChoice> adapter =
|
||||
new ArrayAdapter<KeyEditor.UsageChoice>(getContext(),
|
||||
android.R.layout.simple_spinner_item,
|
||||
choices);
|
||||
ArrayAdapter<Choice> adapter =
|
||||
new ArrayAdapter<Choice>(getContext(),
|
||||
android.R.layout.simple_spinner_item, choices);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mUsage.setAdapter(adapter);
|
||||
|
||||
@@ -169,18 +150,18 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
}
|
||||
mKeyId.setText(keyId1Str + " " + keyId2Str);
|
||||
|
||||
Vector<KeyEditor.UsageChoice> choices = new Vector<KeyEditor.UsageChoice>();
|
||||
choices.add(new KeyEditor.UsageChoice(KeyEditor.UsageChoice.SIGN_ONLY,
|
||||
getResources().getString(R.string.sign_only)));
|
||||
Vector<Choice> choices = new Vector<Choice>();
|
||||
choices.add(new Choice(Id.choice.usage.sign_only,
|
||||
getResources().getString(R.string.sign_only)));
|
||||
if (!mIsMasterKey) {
|
||||
choices.add(new KeyEditor.UsageChoice(KeyEditor.UsageChoice.ENCRYPT_ONLY,
|
||||
getResources().getString(R.string.encrypt_only)));
|
||||
choices.add(new Choice(Id.choice.usage.encrypt_only,
|
||||
getResources().getString(R.string.encrypt_only)));
|
||||
}
|
||||
choices.add(new KeyEditor.UsageChoice(KeyEditor.UsageChoice.SIGN_AND_ENCRYPT,
|
||||
getResources().getString(R.string.sign_and_encrypt)));
|
||||
choices.add(new Choice(Id.choice.usage.sign_and_encrypt,
|
||||
getResources().getString(R.string.sign_and_encrypt)));
|
||||
|
||||
ArrayAdapter<KeyEditor.UsageChoice> adapter =
|
||||
new ArrayAdapter<KeyEditor.UsageChoice>(getContext(),
|
||||
ArrayAdapter<Choice> adapter =
|
||||
new ArrayAdapter<Choice>(getContext(),
|
||||
android.R.layout.simple_spinner_item,
|
||||
choices);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
@@ -242,7 +223,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
return mExpiryDate;
|
||||
}
|
||||
|
||||
public UsageChoice getUsage() {
|
||||
return (UsageChoice) mUsage.getSelectedItem();
|
||||
public int getUsage() {
|
||||
return ((Choice) mUsage.getSelectedItem()).getId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,10 @@ import java.util.Vector;
|
||||
import org.bouncycastle2.openpgp.PGPException;
|
||||
import org.bouncycastle2.openpgp.PGPSecretKey;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.ui.widget.Editor.EditorListener;
|
||||
import org.thialfihar.android.apg.utils.Choice;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
@@ -57,7 +59,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
private TextView mTitle;
|
||||
private int mType = 0;
|
||||
|
||||
private KeyEditor.AlgorithmChoice mNewKeyAlgorithmChoice;
|
||||
private Choice mNewKeyAlgorithmChoice;
|
||||
private int mNewKeySize;
|
||||
|
||||
volatile private PGPSecretKey mNewKey;
|
||||
@@ -181,24 +183,23 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
dialog.setTitle("Create Key");
|
||||
|
||||
final Spinner algorithm = (Spinner) view.findViewById(R.id.algorithm);
|
||||
KeyEditor.AlgorithmChoice choices[] = {
|
||||
new KeyEditor.AlgorithmChoice(KeyEditor.AlgorithmChoice.DSA,
|
||||
getResources().getString(R.string.dsa)),
|
||||
/*new KeyEditor.AlgorithmChoice(KeyEditor.AlgorithmChoice.ELGAMAL,
|
||||
getResources().getString(R.string.elgamal)),*/
|
||||
new KeyEditor.AlgorithmChoice(KeyEditor.AlgorithmChoice.RSA,
|
||||
getResources().getString(R.string.rsa)),
|
||||
Choice choices[] = {
|
||||
new Choice(Id.choice.algorithm.dsa,
|
||||
getResources().getString(R.string.dsa)),
|
||||
/*new Choice(Id.choice.algorithm.elgamal,
|
||||
getResources().getString(R.string.elgamal)),*/
|
||||
new Choice(Id.choice.algorithm.rsa,
|
||||
getResources().getString(R.string.rsa)),
|
||||
};
|
||||
ArrayAdapter<KeyEditor.AlgorithmChoice> adapter =
|
||||
new ArrayAdapter<KeyEditor.AlgorithmChoice>(
|
||||
getContext(),
|
||||
android.R.layout.simple_spinner_item,
|
||||
choices);
|
||||
ArrayAdapter<Choice> adapter =
|
||||
new ArrayAdapter<Choice>(getContext(),
|
||||
android.R.layout.simple_spinner_item,
|
||||
choices);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
algorithm.setAdapter(adapter);
|
||||
// make RSA the default
|
||||
for (int i = 0; i < choices.length; ++i) {
|
||||
if (choices[i].getId() == KeyEditor.AlgorithmChoice.RSA) {
|
||||
if (choices[i].getId() == Id.choice.algorithm.rsa) {
|
||||
algorithm.setSelection(i);
|
||||
break;
|
||||
}
|
||||
@@ -217,8 +218,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
mNewKeySize = 0;
|
||||
}
|
||||
|
||||
mNewKeyAlgorithmChoice =
|
||||
(KeyEditor.AlgorithmChoice) algorithm.getSelectedItem();
|
||||
mNewKeyAlgorithmChoice = (Choice) algorithm.getSelectedItem();
|
||||
createKey();
|
||||
}
|
||||
});
|
||||
@@ -294,7 +294,8 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
public void run() {
|
||||
String error = null;
|
||||
try {
|
||||
mNewKey = Apg.createKey(mNewKeyAlgorithmChoice, mNewKeySize, Apg.getPassPhrase());
|
||||
mNewKey = Apg.createKey(mNewKeyAlgorithmChoice.getId(),
|
||||
mNewKeySize, Apg.getPassPhrase());
|
||||
} catch (NoSuchProviderException e) {
|
||||
error = e.getMessage();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
||||
Reference in New Issue
Block a user