get rid of more getMasterKeyId usage, work on getKeyRingsAsArmoredString

This commit is contained in:
Vincent Breitmoser
2014-04-11 03:21:39 +02:00
parent 9af532880c
commit b77fb2fcc0
7 changed files with 107 additions and 94 deletions

View File

@@ -326,10 +326,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
Log.e(Constants.TAG, "Keyring not found: " + e.getMessage(), e);
Toast.makeText(this, R.string.error_no_secret_key_found, Toast.LENGTH_SHORT).show();
finish();
} catch (PGPException e) {
Log.e(Constants.TAG, "Error extracting key: " + e.getMessage(), e);
Toast.makeText(this, R.string.error_no_secret_key_found, Toast.LENGTH_LONG).show();
finish();
}
}

View File

@@ -165,10 +165,11 @@ public class EncryptAsymmetricFragment extends Fragment {
if (preselectedEncryptionKeyIds != null) {
Vector<Long> goodIds = new Vector<Long>();
for (int i = 0; i < preselectedEncryptionKeyIds.length; ++i) {
// TODO check for available encrypt keys... is this even relevant?
// TODO One query per selected key?! wtf
try {
long id = ProviderHelper.getMasterKeyId(getActivity(),
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(preselectedEncryptionKeyIds[i]))
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(
Long.toString(preselectedEncryptionKeyIds[i]))
);
goodIds.add(id);
} catch (ProviderHelper.NotFoundException e) {

View File

@@ -219,12 +219,8 @@ public class ViewKeyActivity extends ActionBarActivity {
} else {
// get public keyring as ascii armored string
try {
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
this, new long[]{masterKeyId});
content = keyringArmored.get(0);
Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(dataUri);
content = ProviderHelper.getKeyRingAsArmoredString(this, uri);
// Android will fail with android.os.TransactionTooLargeException if key is too big
// see http://www.lonestarprod.com/?p=34
@@ -233,8 +229,12 @@ public class ViewKeyActivity extends ActionBarActivity {
AppMsg.STYLE_ALERT).show();
return;
}
} catch (IOException e) {
Log.e(Constants.TAG, "error processing key!", e);
AppMsg.makeText(this, R.string.error_invalid_data, AppMsg.STYLE_ALERT).show();
} catch (ProviderHelper.NotFoundException e) {
Log.e(Constants.TAG, "key not found!", e);
AppMsg.makeText(this, R.string.error_key_not_found, AppMsg.STYLE_ALERT).show();
}
}
@@ -259,16 +259,18 @@ public class ViewKeyActivity extends ActionBarActivity {
private void copyToClipboard(Uri dataUri) {
// get public keyring as ascii armored string
try {
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(dataUri);
String keyringArmored = ProviderHelper.getKeyRingAsArmoredString(this, uri);
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
this, new long[]{masterKeyId});
ClipboardReflection.copyToClipboard(this, keyringArmored.get(0));
ClipboardReflection.copyToClipboard(this, keyringArmored);
AppMsg.makeText(this, R.string.key_copied_to_clipboard, AppMsg.STYLE_INFO)
.show();
} catch (IOException e) {
Log.e(Constants.TAG, "error processing key!", e);
AppMsg.makeText(this, R.string.error_key_processing, AppMsg.STYLE_ALERT).show();
} catch (ProviderHelper.NotFoundException e) {
Log.e(Constants.TAG, "key not found!", e);
AppMsg.makeText(this, R.string.error_key_not_found, AppMsg.STYLE_ALERT).show();
}
}

View File

@@ -28,14 +28,19 @@ import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.devspark.appmsg.AppMsg;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.QrCodeUtils;
import java.io.IOException;
import java.util.ArrayList;
public class ShareQrCodeDialogFragment extends DialogFragment {
@@ -106,20 +111,18 @@ public class ShareQrCodeDialogFragment extends DialogFragment {
} else {
mText.setText(R.string.share_qr_code_dialog_start);
// TODO works, but
long masterKeyId = 0;
try {
masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(dataUri);
content = ProviderHelper.getKeyRingAsArmoredString(getActivity(), uri);
} catch (IOException e) {
Log.e(Constants.TAG, "error processing key!", e);
AppMsg.makeText(getActivity(), R.string.error_invalid_data, AppMsg.STYLE_ALERT).show();
return null;
} catch (ProviderHelper.NotFoundException e) {
Log.e(Constants.TAG, "key not found!", e);
AppMsg.makeText(getActivity(), R.string.error_key_not_found, AppMsg.STYLE_ALERT).show();
return null;
}
// get public keyring as ascii armored string
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
getActivity(), new long[] { masterKeyId });
// TODO: binary?
content = keyringArmored.get(0);
// OnClickListener are set in onResume to prevent automatic dismissing of Dialogs
// http://bit.ly/O5vfaR