use long rather than String to build uris by key

This commit is contained in:
Vincent Breitmoser 2014-05-21 21:21:28 +02:00
parent 761d87b661
commit ab6c47a9b3
13 changed files with 33 additions and 37 deletions

View File

@ -249,8 +249,7 @@ public class PgpDecryptVerify {
try { try {
// get actual keyring object based on master key id // get actual keyring object based on master key id
secretKeyRing = mProviderHelper.getWrappedSecretKeyRing( secretKeyRing = mProviderHelper.getWrappedSecretKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(encData.getKeyID())
Long.toString(encData.getKeyID()))
); );
} catch (ProviderHelper.NotFoundException e) { } catch (ProviderHelper.NotFoundException e) {
// continue with the next packet in the while loop // continue with the next packet in the while loop
@ -394,9 +393,7 @@ public class PgpDecryptVerify {
try { try {
long sigKeyId = sigList.get(i).getKeyID(); long sigKeyId = sigList.get(i).getKeyID();
signingRing = mProviderHelper.getWrappedPublicKeyRing( signingRing = mProviderHelper.getWrappedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId)
Long.toString(sigKeyId)
)
); );
signingKey = signingRing.getSubkey(sigKeyId); signingKey = signingRing.getSubkey(sigKeyId);
signatureIndex = i; signatureIndex = i;
@ -581,9 +578,7 @@ public class PgpDecryptVerify {
try { try {
long sigKeyId = sigList.get(i).getKeyID(); long sigKeyId = sigList.get(i).getKeyID();
signingRing = mProviderHelper.getWrappedPublicKeyRing( signingRing = mProviderHelper.getWrappedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId)
Long.toString(sigKeyId)
)
); );
signingKey = signingRing.getSubkey(sigKeyId); signingKey = signingRing.getSubkey(sigKeyId);
signatureIndex = i; signatureIndex = i;

View File

@ -317,7 +317,7 @@ public class PgpSignEncrypt {
for (long id : mEncryptionMasterKeyIds) { for (long id : mEncryptionMasterKeyIds) {
try { try {
WrappedPublicKeyRing keyRing = mProviderHelper.getWrappedPublicKeyRing( WrappedPublicKeyRing keyRing = mProviderHelper.getWrappedPublicKeyRing(
KeyRings.buildUnifiedKeyRingUri(Long.toString(id))); KeyRings.buildUnifiedKeyRingUri(id));
WrappedPublicKey key = keyRing.getEncryptionSubKey(); WrappedPublicKey key = keyRing.getEncryptionSubKey();
cPk.addMethod(key.getPubKeyEncryptionGenerator()); cPk.addMethod(key.getPubKeyEncryptionGenerator());
} catch (PgpGeneralException e) { } catch (PgpGeneralException e) {

View File

@ -137,20 +137,24 @@ public class KeychainContract {
return CONTENT_URI.buildUpon().appendPath(uri.getPathSegments().get(1)).build(); return CONTENT_URI.buildUpon().appendPath(uri.getPathSegments().get(1)).build();
} }
public static Uri buildUnifiedKeyRingUri(String masterKeyId) { public static Uri buildUnifiedKeyRingUri(long masterKeyId) {
return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_UNIFIED).build(); return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId))
.appendPath(PATH_UNIFIED).build();
} }
public static Uri buildUnifiedKeyRingUri(Uri uri) { public static Uri buildUnifiedKeyRingUri(Uri uri) {
return CONTENT_URI.buildUpon().appendPath(uri.getPathSegments().get(1)).appendPath(PATH_UNIFIED).build(); return CONTENT_URI.buildUpon().appendPath(uri.getPathSegments().get(1))
.appendPath(PATH_UNIFIED).build();
} }
public static Uri buildUnifiedKeyRingsFindByEmailUri(String email) { public static Uri buildUnifiedKeyRingsFindByEmailUri(String email) {
return CONTENT_URI.buildUpon().appendPath(PATH_FIND).appendPath(PATH_BY_EMAIL).appendPath(email).build(); return CONTENT_URI.buildUpon().appendPath(PATH_FIND)
.appendPath(PATH_BY_EMAIL).appendPath(email).build();
} }
public static Uri buildUnifiedKeyRingsFindBySubkeyUri(String subkey) { public static Uri buildUnifiedKeyRingsFindBySubkeyUri(long subkey) {
return CONTENT_URI.buildUpon().appendPath(PATH_FIND).appendPath(PATH_BY_SUBKEY).appendPath(subkey).build(); return CONTENT_URI.buildUpon().appendPath(PATH_FIND)
.appendPath(PATH_BY_SUBKEY).appendPath(Long.toString(subkey)).build();
} }
} }

View File

@ -644,7 +644,7 @@ public class KeychainProvider extends ContentProvider {
} }
if(keyId != null) { if(keyId != null) {
uri = KeyRings.buildGenericKeyRingUri(keyId.toString()); uri = KeyRings.buildGenericKeyRingUri(keyId);
rowUri = uri; rowUri = uri;
} }

View File

@ -144,7 +144,7 @@ public class ProviderHelper {
public HashMap<String, Object> getUnifiedData(long masterKeyId, String[] proj, int[] types) public HashMap<String, Object> getUnifiedData(long masterKeyId, String[] proj, int[] types)
throws NotFoundException { throws NotFoundException {
return getGenericData(KeyRings.buildUnifiedKeyRingUri(Long.toString(masterKeyId)), proj, types); return getGenericData(KeyRings.buildUnifiedKeyRingUri(masterKeyId), proj, types);
} }
/** /**
@ -202,8 +202,7 @@ public class ProviderHelper {
} }
public WrappedPublicKeyRing getWrappedPublicKeyRing(long id) throws NotFoundException { public WrappedPublicKeyRing getWrappedPublicKeyRing(long id) throws NotFoundException {
return (WrappedPublicKeyRing) getWrappedKeyRing( return (WrappedPublicKeyRing) getWrappedKeyRing(KeyRings.buildUnifiedKeyRingUri(id), false);
KeyRings.buildUnifiedKeyRingUri(Long.toString(id)), false);
} }
public WrappedPublicKeyRing getWrappedPublicKeyRing(Uri queryUri) throws NotFoundException { public WrappedPublicKeyRing getWrappedPublicKeyRing(Uri queryUri) throws NotFoundException {
@ -211,8 +210,7 @@ public class ProviderHelper {
} }
public WrappedSecretKeyRing getWrappedSecretKeyRing(long id) throws NotFoundException { public WrappedSecretKeyRing getWrappedSecretKeyRing(long id) throws NotFoundException {
return (WrappedSecretKeyRing) getWrappedKeyRing( return (WrappedSecretKeyRing) getWrappedKeyRing(KeyRings.buildUnifiedKeyRingUri(id), true);
KeyRings.buildUnifiedKeyRingUri(Long.toString(id)), true);
} }
public WrappedSecretKeyRing getWrappedSecretKeyRing(Uri queryUri) throws NotFoundException { public WrappedSecretKeyRing getWrappedSecretKeyRing(Uri queryUri) throws NotFoundException {

View File

@ -426,7 +426,7 @@ public class OpenPgpService extends RemoteService {
// also return PendingIntent that opens the key view activity // also return PendingIntent that opens the key view activity
Intent intent = new Intent(getBaseContext(), ViewKeyActivity.class); Intent intent = new Intent(getBaseContext(), ViewKeyActivity.class);
intent.setData(KeyRings.buildGenericKeyRingUri(Long.toString(masterKeyId))); intent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId));
PendingIntent pi = PendingIntent.getActivity(getBaseContext(), 0, PendingIntent pi = PendingIntent.getActivity(getBaseContext(), 0,
intent, intent,

View File

@ -179,7 +179,7 @@ public class PassphraseCacheService extends Service {
try { try {
Log.d(TAG, "getCachedPassphraseImpl() for masterKeyId " + keyId); Log.d(TAG, "getCachedPassphraseImpl() for masterKeyId " + keyId);
WrappedSecretKeyRing key = new ProviderHelper(this).getWrappedSecretKeyRing( WrappedSecretKeyRing key = new ProviderHelper(this).getWrappedSecretKeyRing(
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId))); KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId));
// no passphrase needed? just add empty string and return it, then // no passphrase needed? just add empty string and return it, then
if (!key.hasPassphrase()) { if (!key.hasPassphrase()) {
Log.d(Constants.TAG, "Key has no passphrase! Caches and returns empty passphrase!"); Log.d(Constants.TAG, "Key has no passphrase! Caches and returns empty passphrase!");

View File

@ -587,8 +587,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
Intent data = new Intent(); Intent data = new Intent();
// return uri pointing to new created key // return uri pointing to new created key
Uri uri = KeyRings.buildGenericKeyRingUri( Uri uri = KeyRings.buildGenericKeyRingUri(getMasterKeyId());
String.valueOf(getMasterKeyId()));
data.setData(uri); data.setData(uri);
setResult(RESULT_OK, data); setResult(RESULT_OK, data);

View File

@ -32,8 +32,9 @@ import com.beardedhen.androidbootstrap.BootstrapButton;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@ -147,12 +148,13 @@ public class EncryptAsymmetricFragment extends Fragment {
// not sure if we need to distinguish between different subkeys here? // not sure if we need to distinguish between different subkeys here?
if (preselectedSignatureKeyId != 0) { if (preselectedSignatureKeyId != 0) {
try { try {
WrappedPublicKeyRing keyring = CachedPublicKeyRing keyring =
providerHelper.getWrappedPublicKeyRing(preselectedSignatureKeyId); providerHelper.getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingUri(preselectedSignatureKeyId));
if(keyring.hasAnySecret()) { if(keyring.hasAnySecret()) {
setSignatureKeyId(keyring.getMasterKeyId()); setSignatureKeyId(keyring.getMasterKeyId());
} }
} catch (ProviderHelper.NotFoundException e) { } catch (PgpGeneralException e) {
Log.e(Constants.TAG, "key not found!", e); Log.e(Constants.TAG, "key not found!", e);
} }
} }
@ -163,7 +165,7 @@ public class EncryptAsymmetricFragment extends Fragment {
try { try {
long id = providerHelper.getMasterKeyId( long id = providerHelper.getMasterKeyId(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(
Long.toString(preselectedEncryptionKeyIds[i])) preselectedEncryptionKeyIds[i])
); );
goodIds.add(id); goodIds.add(id);
} catch (ProviderHelper.NotFoundException e) { } catch (ProviderHelper.NotFoundException e) {

View File

@ -308,7 +308,7 @@ public class KeyListFragment extends LoaderFragment
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent viewIntent = new Intent(getActivity(), ViewKeyActivity.class); Intent viewIntent = new Intent(getActivity(), ViewKeyActivity.class);
viewIntent.setData( viewIntent.setData(
KeyRings.buildGenericKeyRingUri(Long.toString(mAdapter.getMasterKeyId(position)))); KeyRings.buildGenericKeyRingUri(mAdapter.getMasterKeyId(position)));
startActivity(viewIntent); startActivity(viewIntent);
} }

View File

@ -84,7 +84,7 @@ public class SelectSecretKeyFragment extends ListFragment implements
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
long masterKeyId = mAdapter.getMasterKeyId(position); long masterKeyId = mAdapter.getMasterKeyId(position);
Uri result = KeyRings.buildGenericKeyRingUri(String.valueOf(masterKeyId)); Uri result = KeyRings.buildGenericKeyRingUri(masterKeyId);
// return data to activity, which results in finishing it // return data to activity, which results in finishing it
mActivity.afterListSelection(result); mActivity.afterListSelection(result);

View File

@ -132,7 +132,7 @@ public class SelectSecretKeyLayoutFragment extends Fragment implements LoaderMan
//For AppSettingsFragment //For AppSettingsFragment
public void selectKey(long masterKeyId) { public void selectKey(long masterKeyId) {
Uri buildUri = KeychainContract.KeyRings.buildGenericKeyRingUri(String.valueOf(masterKeyId)); Uri buildUri = KeychainContract.KeyRings.buildGenericKeyRingUri(masterKeyId);
mReceivedUri = buildUri; mReceivedUri = buildUri;
getActivity().getSupportLoaderManager().restartLoader(LOADER_ID, null, this); getActivity().getSupportLoaderManager().restartLoader(LOADER_ID, null, this);
} }

View File

@ -212,11 +212,9 @@ public class ViewCertActivity extends ActionBarActivity
try { try {
ProviderHelper providerHelper = new ProviderHelper(ViewCertActivity.this); ProviderHelper providerHelper = new ProviderHelper(ViewCertActivity.this);
long signerMasterKeyId = providerHelper.getMasterKeyId( long signerMasterKeyId = providerHelper.getMasterKeyId(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(mCertifierKeyId)) KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)
);
viewIntent.setData(KeyRings.buildGenericKeyRingUri(
Long.toString(signerMasterKeyId))
); );
viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId));
startActivity(viewIntent); startActivity(viewIntent);
} catch (ProviderHelper.NotFoundException e) { } catch (ProviderHelper.NotFoundException e) {
// TODO notify user of this, maybe offer download? // TODO notify user of this, maybe offer download?