replace calls to getGenericData with getCachedPublicKeyRing equivalents

This commit is contained in:
Vincent Breitmoser
2017-02-20 18:17:15 +01:00
parent 0277ba1afa
commit c2b9af077a
7 changed files with 42 additions and 39 deletions

View File

@@ -63,15 +63,15 @@ public class CanonicalizedSecretKeyRing extends CanonicalizedKeyRing {
}
public CanonicalizedSecretKey getSecretKey() {
return new CanonicalizedSecretKey(this, mRing.getSecretKey());
return new CanonicalizedSecretKey(this, getRing().getSecretKey());
}
public CanonicalizedSecretKey getSecretKey(long id) {
return new CanonicalizedSecretKey(this, mRing.getSecretKey(id));
return new CanonicalizedSecretKey(this, getRing().getSecretKey(id));
}
public IterableIterator<CanonicalizedSecretKey> secretKeyIterator() {
final Iterator<PGPSecretKey> it = mRing.getSecretKeys();
final Iterator<PGPSecretKey> it = getRing().getSecretKeys();
return new IterableIterator<>(new Iterator<CanonicalizedSecretKey>() {
@Override
public boolean hasNext() {

View File

@@ -25,6 +25,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException;
@@ -237,4 +238,12 @@ public class CachedPublicKeyRing extends KeyRing {
return SecretKeyType.fromNum(((Long) data).intValue());
}
public byte[] getEncoded() throws PgpKeyNotFoundException {
try {
return (byte[]) mDatabaseInteractor.getGenericData(mUri, KeyRingData.KEY_RING_DATA,
DatabaseInteractor.FIELD_TYPE_BLOB);
} catch(DatabaseReadWriteInteractor.NotFoundException e) {
throw new PgpKeyNotFoundException(e);
}
}
}

View File

@@ -69,7 +69,7 @@ public class DatabaseInteractor {
mLog = new OperationLog();
}
public Object getGenericData(Uri uri, String column, int type) throws NotFoundException {
Object getGenericData(Uri uri, String column, int type) throws NotFoundException {
Object result = getGenericData(uri, new String[]{column}, new int[]{type}, null).get(column);
if (result == null) {
throw new NotFoundException();
@@ -77,17 +77,17 @@ public class DatabaseInteractor {
return result;
}
public Object getGenericData(Uri uri, String column, int type, String selection)
Object getGenericData(Uri uri, String column, int type, String selection)
throws NotFoundException {
return getGenericData(uri, new String[]{column}, new int[]{type}, selection).get(column);
}
public HashMap<String, Object> getGenericData(Uri uri, String[] proj, int[] types)
private HashMap<String, Object> getGenericData(Uri uri, String[] proj, int[] types)
throws NotFoundException {
return getGenericData(uri, proj, types, null);
}
public HashMap<String, Object> getGenericData(Uri uri, String[] proj, int[] types, String selection)
private HashMap<String, Object> getGenericData(Uri uri, String[] proj, int[] types, String selection)
throws NotFoundException {
Cursor cursor = mContentResolver.query(uri, proj, selection, null, null);

View File

@@ -28,6 +28,7 @@ import android.widget.ImageView;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor;
@@ -77,9 +78,7 @@ public class QrCodeViewActivity extends BaseActivity {
DatabaseInteractor databaseInteractor = new DatabaseInteractor(getContentResolver());
try {
byte[] blob = (byte[]) databaseInteractor.getGenericData(
KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri),
KeychainContract.KeyRings.FINGERPRINT, DatabaseInteractor.FIELD_TYPE_BLOB);
byte[] blob = databaseInteractor.getCachedPublicKeyRing(dataUri).getFingerprint();
if (blob == null) {
Log.e(Constants.TAG, "key not found!");
Notify.create(this, R.string.error_key_not_found, Style.ERROR).show();
@@ -103,7 +102,7 @@ public class QrCodeViewActivity extends BaseActivity {
mQrCode.setImageBitmap(scaled);
}
});
} catch (DatabaseReadWriteInteractor.NotFoundException e) {
} catch (PgpKeyNotFoundException e) {
Log.e(Constants.TAG, "key not found!", e);
Notify.create(this, R.string.error_key_not_found, Style.ERROR).show();
ActivityCompat.finishAfterTransition(QrCodeViewActivity.this);

View File

@@ -17,6 +17,10 @@
package org.sufficientlysecure.keychain.ui;
import java.io.IOException;
import java.util.ArrayList;
import android.annotation.TargetApi;
import android.content.Intent;
import android.graphics.PorterDuff;
@@ -27,15 +31,18 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.NumberPicker;
import edu.cmu.cylab.starslinger.exchange.ExchangeActivity;
import edu.cmu.cylab.starslinger.exchange.ExchangeConfig;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
import org.sufficientlysecure.keychain.operations.ImportOperation;
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
@@ -43,13 +50,6 @@ import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver;
import java.io.IOException;
import java.util.ArrayList;
import edu.cmu.cylab.starslinger.exchange.ExchangeActivity;
import edu.cmu.cylab.starslinger.exchange.ExchangeConfig;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class SafeSlingerActivity extends BaseActivity
@@ -106,8 +106,7 @@ public class SafeSlingerActivity extends BaseActivity
// retrieve public key blob and start SafeSlinger
Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId);
try {
byte[] keyBlob = (byte[]) new DatabaseInteractor(getContentResolver()).getGenericData(
uri, KeychainContract.KeyRingData.KEY_RING_DATA, DatabaseInteractor.FIELD_TYPE_BLOB);
byte[] keyBlob = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(uri).getEncoded();
Intent slingerIntent = new Intent(this, ExchangeActivity.class);
@@ -115,7 +114,7 @@ public class SafeSlingerActivity extends BaseActivity
slingerIntent.putExtra(ExchangeConfig.extra.USER_DATA, keyBlob);
slingerIntent.putExtra(ExchangeConfig.extra.HOST_NAME, Constants.SAFESLINGER_SERVER);
startActivityForResult(slingerIntent, REQUEST_CODE_SAFE_SLINGER);
} catch (DatabaseReadWriteInteractor.NotFoundException e) {
} catch (PgpKeyNotFoundException e) {
Log.e(Constants.TAG, "personal key not found", e);
}
}

View File

@@ -400,7 +400,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
case R.id.menu_key_view_refresh: {
try {
updateFromKeyserver(mDataUri, mDatabaseInteractor);
} catch (DatabaseInteractor.NotFoundException e) {
} catch (PgpKeyNotFoundException e) {
Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show();
}
return true;
@@ -1119,16 +1119,14 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
private void updateFromKeyserver(Uri dataUri, DatabaseInteractor databaseInteractor)
throws DatabaseInteractor.NotFoundException {
throws PgpKeyNotFoundException {
mIsRefreshing = true;
mRefreshItem.setEnabled(false);
mRefreshItem.setActionView(mRefresh);
mRefresh.startAnimation(mRotate);
byte[] blob = (byte[]) databaseInteractor.getGenericData(
KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri),
KeychainContract.Keys.FINGERPRINT, DatabaseInteractor.FIELD_TYPE_BLOB);
byte[] blob = databaseInteractor.getCachedPublicKeyRing(dataUri).getFingerprint();
String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob);
ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null, null);

View File

@@ -18,6 +18,9 @@
package org.sufficientlysecure.keychain.util;
import java.lang.ref.WeakReference;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
@@ -35,13 +38,11 @@ import android.provider.Settings;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException;
import org.sufficientlysecure.keychain.ui.util.Notify;
import java.lang.ref.WeakReference;
/**
* This class contains NFC functionality that can be shared across Fragments or Activities.
*/
@@ -127,13 +128,10 @@ public class NfcHelper {
new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... unused) {
try {
Uri blobUri =
KeychainContract.KeyRingData.buildPublicKeyRingUri(dataUri);
mNfcKeyringBytes = (byte[]) mDatabaseInteractor.getGenericData(
blobUri,
KeychainContract.KeyRingData.KEY_RING_DATA,
DatabaseInteractor.FIELD_TYPE_BLOB);
} catch (DatabaseReadWriteInteractor.NotFoundException e) {
long masterKeyId = mDatabaseInteractor.getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId();
mNfcKeyringBytes = mDatabaseInteractor.getPublicKeyRingData(masterKeyId);
} catch (NotFoundException | PgpKeyNotFoundException e) {
Log.e(Constants.TAG, "key not found!", e);
}