give key editing its own pass phrase mechanism, as the new cache won't work there

This commit is contained in:
Thialfihar 2010-05-16 13:35:16 +00:00
parent 9855f4d144
commit c7f0041751
3 changed files with 33 additions and 8 deletions

View File

@ -158,6 +158,7 @@ public class Apg {
private static HashMap<Long, CachedPassPhrase> mPassPhraseCache = private static HashMap<Long, CachedPassPhrase> mPassPhraseCache =
new HashMap<Long, CachedPassPhrase>(); new HashMap<Long, CachedPassPhrase>();
private static String mEditPassPhrase = null;
public static class GeneralException extends Exception { public static class GeneralException extends Exception {
static final long serialVersionUID = 0xf812773342L; static final long serialVersionUID = 0xf812773342L;
@ -273,6 +274,14 @@ public class Apg {
} }
} }
public static void setEditPassPhrase(String passPhrase) {
mEditPassPhrase = passPhrase;
}
public static String getEditPassPhrase() {
return mEditPassPhrase;
}
public static void setCachedPassPhrase(long keyId, String passPhrase) { public static void setCachedPassPhrase(long keyId, String passPhrase) {
mPassPhraseCache.put(keyId, new CachedPassPhrase(new Date().getTime(), passPhrase)); mPassPhraseCache.put(keyId, new CachedPassPhrase(new Date().getTime(), passPhrase));
} }

View File

@ -55,6 +55,7 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
private Button mSaveButton; private Button mSaveButton;
private Button mDiscardButton; private Button mDiscardButton;
private String mCurrentPassPhrase = null;
private String mNewPassPhrase = null; private String mNewPassPhrase = null;
@Override @Override
@ -106,6 +107,11 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
mKeys.setKeys(keys); mKeys.setKeys(keys);
container.addView(mKeys); container.addView(mKeys);
mCurrentPassPhrase = Apg.getEditPassPhrase();
if (mCurrentPassPhrase == null) {
mCurrentPassPhrase = "";
}
Toast.makeText(this, "Warning: Key editing is still kind of beta.", Toast.LENGTH_LONG).show(); Toast.makeText(this, "Warning: Key editing is still kind of beta.", Toast.LENGTH_LONG).show();
} }
@ -117,11 +123,7 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
} }
public boolean havePassPhrase() { public boolean havePassPhrase() {
long keyId = getMasterKeyId(); return (!mCurrentPassPhrase.equals("")) ||
if (keyId == 0) {
return false;
}
return (Apg.getCachedPassPhrase(keyId) != null && !Apg.getCachedPassPhrase(keyId).equals("")) ||
(mNewPassPhrase != null && !mNewPassPhrase.equals("")); (mNewPassPhrase != null && !mNewPassPhrase.equals(""));
} }
@ -235,7 +237,7 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
Message msg = new Message(); Message msg = new Message();
try { try {
String oldPassPhrase = Apg.getCachedPassPhrase(getMasterKeyId()); String oldPassPhrase = mCurrentPassPhrase;
String newPassPhrase = mNewPassPhrase; String newPassPhrase = mNewPassPhrase;
if (newPassPhrase == null) { if (newPassPhrase == null) {
newPassPhrase = oldPassPhrase; newPassPhrase = oldPassPhrase;

View File

@ -138,7 +138,7 @@ public class SecretKeyListActivity extends BaseActivity implements OnChildClickL
switch (menuItem.getItemId()) { switch (menuItem.getItemId()) {
case Id.menu.edit: { case Id.menu.edit: {
mSelectedItem = groupPosition; mSelectedItem = groupPosition;
showDialog(Id.dialog.pass_phrase); checkPassPhraseAndEdit();
return true; return true;
} }
@ -164,7 +164,7 @@ public class SecretKeyListActivity extends BaseActivity implements OnChildClickL
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) { int childPosition, long id) {
mSelectedItem = groupPosition; mSelectedItem = groupPosition;
showDialog(Id.dialog.pass_phrase); checkPassPhraseAndEdit();
return true; return true;
} }
@ -269,13 +269,27 @@ public class SecretKeyListActivity extends BaseActivity implements OnChildClickL
} }
} }
public void checkPassPhraseAndEdit() {
PGPSecretKeyRing keyRing = Apg.getSecretKeyRings().get(mSelectedItem);
long keyId = keyRing.getSecretKey().getKeyID();
String passPhrase = Apg.getCachedPassPhrase(keyId);
if (passPhrase == null) {
showDialog(Id.dialog.pass_phrase);
} else {
Apg.setEditPassPhrase(passPhrase);
editKey();
}
}
@Override @Override
public void passPhraseCallback(long keyId, String passPhrase) { public void passPhraseCallback(long keyId, String passPhrase) {
super.passPhraseCallback(keyId, passPhrase); super.passPhraseCallback(keyId, passPhrase);
Apg.setEditPassPhrase(passPhrase);
editKey(); editKey();
} }
private void createKey() { private void createKey() {
Apg.setEditPassPhrase("");
Intent intent = new Intent(this, EditKeyActivity.class); Intent intent = new Intent(this, EditKeyActivity.class);
startActivityForResult(intent, Id.message.create_key); startActivityForResult(intent, Id.message.create_key);
} }