From e6d4b0c70b7d469f2353822e6087bdbc0a549d18 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Tue, 28 Jan 2014 23:03:52 +0000 Subject: [PATCH 1/2] exporting secret keys means exporting public, no need to do so twice --- .../keychain/pgp/PgpImportExport.java | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java index 0a4806239..6f3ae154a 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -206,30 +206,6 @@ public class PgpImportExport { mContext.getString(R.string.error_external_storage_not_ready)); } - // export public keyrings... - ArmoredOutputStream outPub = new ArmoredOutputStream(outStream); - outPub.setHeader("Version", PgpHelper.getFullVersion(mContext)); - - int numKeys = 0; - for (int i = 0; i < keyRingMasterKeyIds.size(); ++i) { - // double the needed time if exporting both public and secret parts - if (keyType == Id.type.secret_key) { - updateProgress(i * 100 / keyRingMasterKeyIds.size() / 2, 100); - } else { - updateProgress(i * 100 / keyRingMasterKeyIds.size(), 100); - } - - PGPPublicKeyRing publicKeyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId( - mContext, keyRingMasterKeyIds.get(i)); - - if (publicKeyRing != null) { - publicKeyRing.encode(outPub); - } - ++numKeys; - } - outPub.close(); - - // if we export secret keyrings, append all secret parts after the public parts if (keyType == Id.type.secret_key) { ArmoredOutputStream outSec = new ArmoredOutputStream(outStream); outSec.setHeader("Version", PgpHelper.getFullVersion(mContext)); @@ -245,9 +221,30 @@ public class PgpImportExport { } } outSec.close(); + } else { + // export public keyrings... + ArmoredOutputStream outPub = new ArmoredOutputStream(outStream); + outPub.setHeader("Version", PgpHelper.getFullVersion(mContext)); + + for (int i = 0; i < keyRingMasterKeyIds.size(); ++i) { + // double the needed time if exporting both public and secret parts + if (keyType == Id.type.secret_key) { + updateProgress(i * 100 / keyRingMasterKeyIds.size() / 2, 100); + } else { + updateProgress(i * 100 / keyRingMasterKeyIds.size(), 100); + } + + PGPPublicKeyRing publicKeyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId( + mContext, keyRingMasterKeyIds.get(i)); + + if (publicKeyRing != null) { + publicKeyRing.encode(outPub); + } + } + outPub.close(); } - returnData.putInt(KeychainIntentService.RESULT_EXPORT, numKeys); + returnData.putInt(KeychainIntentService.RESULT_EXPORT, keyRingMasterKeyIds.size()); updateProgress(R.string.progress_done, 100, 100); From 2d4b2ae0dfeaa330b1d061e9a28244b09717516a Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Tue, 28 Jan 2014 23:55:27 +0000 Subject: [PATCH 2/2] show import secret key userID --- .../keychain/ui/adapter/ImportKeysAdapter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 41539d0f8..77d4b9a26 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -98,8 +98,9 @@ public class ImportKeysAdapter extends ArrayAdapter { if (userIdSplit[0] != null && userIdSplit[0].length() > 0) { // show red user id if it is a secret key if (entry.secretKey) { - userId = mActivity.getString(R.string.secret_key) + " " + userId; + userId = mActivity.getString(R.string.secret_key) + " " + userIdSplit[0]; mainUserId.setTextColor(Color.RED); + mainUserId.setText(userId); } else { mainUserId.setText(userIdSplit[0]); }