focus key deletion into KeyWritableRepository
This commit is contained in:
parent
9cf0b05202
commit
05e4cf1ab6
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.sufficientlysecure.keychain.operations;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
|
@ -27,7 +28,6 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp
|
|||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
|
||||
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
||||
import org.sufficientlysecure.keychain.service.DeleteKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
|
@ -81,10 +81,8 @@ public class DeleteOperation extends BaseReadWriteOperation<DeleteKeyringParcel>
|
|||
cancelled = true;
|
||||
break;
|
||||
}
|
||||
int count = mKeyRepository.getContentResolver().delete(
|
||||
KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null
|
||||
);
|
||||
if (count > 0) {
|
||||
boolean deleteSuccess = mKeyWritableRepository.deleteKeyRing(masterKeyId);
|
||||
if (deleteSuccess) {
|
||||
log.add(LogType.MSG_DEL_KEY, 1, KeyFormattingUtils.beautifyKeyId(masterKeyId));
|
||||
success += 1;
|
||||
} else {
|
||||
|
|
|
@ -18,16 +18,16 @@
|
|||
|
||||
package org.sufficientlysecure.keychain.provider;
|
||||
|
||||
import android.database.Cursor;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
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.KeyRepository.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
/** This implementation of KeyRing provides a cached view of PublicKeyRing
|
||||
|
@ -224,11 +224,6 @@ public class CachedPublicKeyRing extends KeyRing {
|
|||
}
|
||||
}
|
||||
|
||||
private Cursor getSubkeys() throws PgpKeyNotFoundException {
|
||||
Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId());
|
||||
return mKeyRepository.getContentResolver().query(keysUri, null, null, null, null);
|
||||
}
|
||||
|
||||
public SecretKeyType getSecretKeyType(long keyId) throws NotFoundException {
|
||||
Object data = mKeyRepository.getGenericData(Keys.buildKeysUri(mUri),
|
||||
KeyRings.HAS_SECRET,
|
||||
|
|
|
@ -552,7 +552,7 @@ public class KeyWritableRepository extends KeyRepository {
|
|||
lastUpdatedCursor.close();
|
||||
|
||||
try {
|
||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||
// delete old version of this keyRing (from database only!), which also deletes all keys and userIds on cascade
|
||||
int deleted = mContentResolver.delete(
|
||||
KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null);
|
||||
if (deleted > 0) {
|
||||
|
@ -611,6 +611,17 @@ public class KeyWritableRepository extends KeyRepository {
|
|||
return mContentResolver.insert(uri, values);
|
||||
}
|
||||
|
||||
public boolean deleteKeyRing(long masterKeyId) {
|
||||
try {
|
||||
mLocalPublicKeyStorage.deletePublicKey(masterKeyId);
|
||||
} catch (IOException e) {
|
||||
android.util.Log.e(Constants.TAG, "Could not delete file!", e);
|
||||
return false;
|
||||
}
|
||||
int deletedRows = mContentResolver.delete(KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null);
|
||||
return deletedRows > 0;
|
||||
}
|
||||
|
||||
private static class UserPacketItem implements Comparable<UserPacketItem> {
|
||||
Integer type;
|
||||
String userId;
|
||||
|
|
|
@ -75,4 +75,14 @@ class LocalPublicKeyStorage {
|
|||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
void deletePublicKey(long masterKeyId) throws IOException {
|
||||
File publicKeyFile = getPublicKeyFile(masterKeyId);
|
||||
if (publicKeyFile.exists()) {
|
||||
boolean deleteSuccess = publicKeyFile.delete();
|
||||
if (!deleteSuccess) {
|
||||
throw new IOException("File exists, but could not be deleted!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue