slight cleanup

This commit is contained in:
Vincent Breitmoser
2017-09-23 00:46:06 +02:00
parent b814753b3b
commit 678a5c1562
42 changed files with 101 additions and 106 deletions

View File

@@ -96,7 +96,7 @@ public class TestHelpers {
IteratorWithIOThrow<UncachedKeyRing> stream = UncachedKeyRing.fromStream(
getInstrumentation().getContext().getAssets().open(name));
KeyWritableRepository helper = KeyWritableRepository.createDatabaseReadWriteInteractor(context);
KeyWritableRepository helper = KeyWritableRepository.create(context);
while(stream.hasNext()) {
UncachedKeyRing ring = stream.next();
if (ring.isSecret()) {

View File

@@ -37,7 +37,7 @@ public abstract class CustomActions {
public static ViewAction tokenEncryptViewAddToken(long keyId) throws Exception {
CanonicalizedPublicKeyRing ring =
KeyWritableRepository.createDatabaseReadWriteInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId);
KeyWritableRepository.create(getTargetContext()).getCanonicalizedPublicKeyRing(keyId);
final Object item = new KeyAdapter.KeyItem(ring);
return new ViewAction() {

View File

@@ -42,7 +42,7 @@ public class KeyRepository {
OperationLog mLog;
int mIndent;
public static KeyRepository createDatabaseInteractor(Context context) {
public static KeyRepository create(Context context) {
ContentResolver contentResolver = context.getContentResolver();
LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(context);

View File

@@ -83,9 +83,7 @@ import org.sufficientlysecure.keychain.util.Utf8Util;
public class KeyWritableRepository extends KeyRepository {
private static final int MAX_CACHED_KEY_SIZE = 1024 * 50;
private final Context mContext;
public static KeyWritableRepository createDatabaseReadWriteInteractor(Context context) {
public static KeyWritableRepository create(Context context) {
LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(context);
return new KeyWritableRepository(context, localPublicKeyStorage);
@@ -99,8 +97,6 @@ public class KeyWritableRepository extends KeyRepository {
private KeyWritableRepository(
Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log, int indent) {
super(context.getContentResolver(), localPublicKeyStorage, log, indent);
mContext = context;
}
private LongSparseArray<CanonicalizedPublicKey> getTrustedMasterKeys() {

View File

@@ -104,7 +104,7 @@ public class OpenPgpService extends Service {
@Override
public void onCreate() {
super.onCreate();
mKeyRepository = KeyRepository.createDatabaseInteractor(this);
mKeyRepository = KeyRepository.create(this);
mApiDao = new ApiDataAccessObject(this);
mApiPermissionHelper = new ApiPermissionHelper(this, mApiDao);
mApiPendingIntentFactory = new ApiPendingIntentFactory(getBaseContext());
@@ -491,7 +491,7 @@ public class OpenPgpService extends Service {
return null;
}
// this will merge if the key already exists - no worries!
KeyWritableRepository.createDatabaseReadWriteInteractor(this).savePublicKeyRing(uncachedKeyRing);
KeyWritableRepository.create(this).savePublicKeyRing(uncachedKeyRing);
newMasterKeyId = uncachedKeyRing.getMasterKeyId();
} else {
newMasterKeyId = null;

View File

@@ -41,7 +41,7 @@ class RequestKeyPermissionPresenter {
ApiDataAccessObject apiDataAccessObject = new ApiDataAccessObject(context);
ApiPermissionHelper apiPermissionHelper = new ApiPermissionHelper(context, apiDataAccessObject);
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(context);
KeyRepository.create(context);
return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager,
keyRepository);

View File

@@ -112,7 +112,7 @@ public class KeychainService extends Service implements Progressable {
// just for brevity
KeychainService outerThis = KeychainService.this;
KeyWritableRepository databaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(outerThis);
KeyWritableRepository.create(outerThis);
if (inputParcel instanceof SignEncryptParcel) {
op = new SignEncryptOperation(outerThis, databaseInteractor, outerThis, mActionCanceled);
} else if (inputParcel instanceof PgpDecryptVerifyInputParcel) {

View File

@@ -322,7 +322,7 @@ public class KeyserverSyncAdapterService extends Service {
CryptoInputParcel cryptoInputParcel) {
Log.d(Constants.TAG, "Starting normal update");
ImportOperation importOp = new ImportOperation(context,
KeyWritableRepository.createDatabaseReadWriteInteractor(context), null);
KeyWritableRepository.create(context), null);
return importOp.execute(
ImportKeyringParcel.createImportKeyringParcel(keyList,
Preferences.getPreferences(context).getPreferredKeyserver()),
@@ -381,7 +381,7 @@ public class KeyserverSyncAdapterService extends Service {
new OperationResult.OperationLog());
}
ImportKeyResult result =
new ImportOperation(context, KeyWritableRepository.createDatabaseReadWriteInteractor(context), null, mCancelled)
new ImportOperation(context, KeyWritableRepository.create(context), null, mCancelled)
.execute(
ImportKeyringParcel.createImportKeyringParcel(
keyWrapper,

View File

@@ -245,7 +245,7 @@ public class PassphraseCacheService extends Service {
+ masterKeyId + ", subKeyId " + subKeyId);
// get the type of key (from the database)
CachedPublicKeyRing keyRing = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId);
CachedPublicKeyRing keyRing = KeyRepository.create(this).getCachedPublicKeyRing(masterKeyId);
SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId);
switch (keyType) {

View File

@@ -214,7 +214,7 @@ public class CertifyFingerprintFragment extends LoaderFragment implements
private void certify(Uri dataUri) {
long keyId = 0;
try {
keyId = KeyRepository.createDatabaseInteractor(getContext())
keyId = KeyRepository.create(getContext())
.getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) {

View File

@@ -70,7 +70,7 @@ public class CertifyKeyFragment
if (certifyKeyId != Constants.key.none) {
try {
CachedPublicKeyRing key = (KeyRepository
.createDatabaseInteractor(getContext()))
.create(getContext()))
.getCachedPublicKeyRing(certifyKeyId);
if (key.canCertify()) {
mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId);

View File

@@ -430,7 +430,7 @@ public class CreateKeyFinalFragment extends Fragment {
CreateKeyActivity activity = (CreateKeyActivity) getActivity();
SaveKeyringParcel.Builder builder;
CachedPublicKeyRing key = (KeyRepository.createDatabaseInteractor(getContext()))
CachedPublicKeyRing key = (KeyRepository.create(getContext()))
.getCachedPublicKeyRing(saveKeyResult.mMasterKeyId);
try {
builder = SaveKeyringParcel.buildChangeKeyringParcel(key.getMasterKeyId(), key.getFingerprint());

View File

@@ -194,7 +194,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
try {
Intent viewKeyIntent = new Intent(getActivity(), ViewKeyActivity.class);
long masterKeyId = KeyRepository.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(
long masterKeyId = KeyRepository.create(getContext()).getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId)
).getMasterKeyId();
viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId));

View File

@@ -89,7 +89,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
if (mMasterKeyIds.length == 1 && mHasSecret) {
// if mMasterKeyIds.length == 0 we let the DeleteOperation respond
try {
HashMap<String, Object> data = KeyRepository.createDatabaseInteractor(this).getUnifiedData(
HashMap<String, Object> data = KeyRepository.create(this).getUnifiedData(
mMasterKeyIds[0], new String[]{
KeychainContract.KeyRings.NAME,
KeychainContract.KeyRings.IS_REVOKED
@@ -272,7 +272,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
long masterKeyId = masterKeyIds[0];
try {
HashMap<String, Object> data = KeyRepository.createDatabaseInteractor(getContext())
HashMap<String, Object> data = KeyRepository.create(getContext())
.getUnifiedData(
masterKeyId, new String[]{
KeychainContract.KeyRings.NAME,

View File

@@ -170,7 +170,7 @@ public class EditIdentitiesFragment extends Fragment
try {
Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri);
CachedPublicKeyRing keyRing =
KeyRepository.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(secretUri);
KeyRepository.create(getContext()).getCachedPublicKeyRing(secretUri);
long masterKeyId = keyRing.getMasterKeyId();
// check if this is a master secret key we can work with

View File

@@ -201,7 +201,7 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment<SaveKeyring
try {
Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri);
CachedPublicKeyRing keyRing =
KeyRepository.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(secretUri);
KeyRepository.create(getContext()).getCachedPublicKeyRing(secretUri);
long masterKeyId = keyRing.getMasterKeyId();
// check if this is a master secret key we can work with

View File

@@ -118,7 +118,7 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mKeyRepository = KeyRepository.createDatabaseInteractor(getContext());
mKeyRepository = KeyRepository.create(getContext());
// preselect keys given, from state or arguments
if (savedInstanceState == null) {

View File

@@ -477,7 +477,7 @@ public class KeyListFragment extends RecyclerFragment<KeySectionedListAdapter>
}
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(getContext());
KeyRepository.create(getContext());
Cursor cursor = keyRepository.getContentResolver().query(
KeyRings.buildUnifiedKeyRingsUri(), new String[]{
KeyRings.FINGERPRINT

View File

@@ -112,7 +112,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
// handle empty passphrases by directly returning an empty crypto input parcel
try {
CachedPublicKeyRing pubRing =
KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId());
KeyRepository.create(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId());
// use empty passphrase for empty passphrase
if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) {
// also return passphrase back to activity
@@ -234,7 +234,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
long subKeyId = mRequiredInput.getSubKeyId();
KeyRepository helper =
KeyRepository.createDatabaseInteractor(getContext());
KeyRepository.create(getContext());
CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing(
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
// yes the inner try/catch block is necessary, otherwise the final variable
@@ -454,7 +454,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
Long subKeyId = mRequiredInput.getSubKeyId();
CanonicalizedSecretKeyRing secretKeyRing =
KeyRepository.createDatabaseInteractor(getContext()).getCanonicalizedSecretKeyRing(
KeyRepository.create(getContext()).getCanonicalizedSecretKeyRing(
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
CanonicalizedSecretKey secretKeyToUnlock =
secretKeyRing.getSecretKey(subKeyId);

View File

@@ -74,7 +74,7 @@ public class QrCodeViewActivity extends BaseActivity {
}
});
KeyRepository keyRepository = KeyRepository.createDatabaseInteractor(this);
KeyRepository keyRepository = KeyRepository.create(this);
try {
byte[] blob = keyRepository.getCachedPublicKeyRing(dataUri).getFingerprint();
if (blob == null) {

View File

@@ -106,7 +106,7 @@ public class SafeSlingerActivity extends BaseActivity
// retrieve public key blob and start SafeSlinger
Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId);
try {
byte[] keyBlob = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(uri).getEncoded();
byte[] keyBlob = KeyRepository.create(this).getCachedPublicKeyRing(uri).getEncoded();
Intent slingerIntent = new Intent(this, ExchangeActivity.class);

View File

@@ -197,7 +197,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity {
}
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(this);
KeyRepository.create(this);
CanonicalizedPublicKeyRing publicKeyRing;
try {
publicKeyRing = keyRepository.getCanonicalizedPublicKeyRing(
@@ -237,7 +237,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity {
mSecurityTokenHelper.setAdminPin(new Passphrase("12345678"));
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(this);
KeyRepository.create(this);
CanonicalizedSecretKeyRing secretKeyRing;
try {
secretKeyRing = keyRepository.getCanonicalizedSecretKeyRing(

View File

@@ -79,7 +79,7 @@ public class SettingsKeyserverFragment extends Fragment implements RecyclerItemC
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
databaseReadWriteInteractor = KeyWritableRepository.createDatabaseReadWriteInteractor(getContext());
databaseReadWriteInteractor = KeyWritableRepository.create(getContext());
return inflater.inflate(R.layout.settings_keyserver_fragment, null);
}

View File

@@ -189,7 +189,7 @@ public class ViewCertActivity extends BaseActivity
try {
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(ViewCertActivity.this);
KeyRepository.create(ViewCertActivity.this);
long signerMasterKeyId = keyRepository.getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId();
viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId));

View File

@@ -88,7 +88,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements
}
});
mKeyRepository = KeyRepository.createDatabaseInteractor(this);
mKeyRepository = KeyRepository.create(this);
mViewPager = (ViewPager) findViewById(R.id.pager);
mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout);

View File

@@ -181,7 +181,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
private void startSafeSlinger(Uri dataUri) {
long keyId = 0;
try {
keyId = KeyRepository.createDatabaseInteractor(getContext())
keyId = KeyRepository.create(getContext())
.getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) {
@@ -198,7 +198,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
return;
}
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(getContext());
KeyRepository.create(getContext());
try {
long masterKeyId = keyRepository.getCachedPublicKeyRing(mDataUri).extractOrGetMasterKeyId();
@@ -436,7 +436,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
private void uploadToKeyserver() {
long keyId;
try {
keyId = KeyRepository.createDatabaseInteractor(getContext())
keyId = KeyRepository.create(getContext())
.getCachedPublicKeyRing(mDataUri)
.extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) {

View File

@@ -75,7 +75,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
mListener = listener;
mNonInteractive = nonInteractive;
mKeyRepository = KeyRepository.createDatabaseInteractor(activity);
mKeyRepository = KeyRepository.create(activity);
}
public void setData(List<ImportKeysListEntry> data) {

View File

@@ -467,7 +467,7 @@ public class LinkedIdViewFragment extends CryptoOperationFragment implements
byte[] fingerprint;
try {
fingerprint = KeyRepository.createDatabaseInteractor(activity).getCachedPublicKeyRing(
fingerprint = KeyRepository.create(activity).getCachedPublicKeyRing(
mMasterKeyId).getFingerprint();
} catch (PgpKeyNotFoundException e) {
throw new IllegalStateException("Key to verify linked id for must exist in db!");

View File

@@ -175,7 +175,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mKeyRepository = KeyRepository.createDatabaseInteractor(this);
mKeyRepository = KeyRepository.create(this);
mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null);
setTitle(null);
@@ -656,7 +656,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
return;
}
try {
long keyId = KeyRepository.createDatabaseInteractor(this)
long keyId = KeyRepository.create(this)
.getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId();
long[] encryptionKeyIds = new long[]{keyId};
@@ -680,7 +680,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
private void startSafeSlinger(Uri dataUri) {
long keyId = 0;
try {
keyId = KeyRepository.createDatabaseInteractor(this)
keyId = KeyRepository.create(this)
.getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) {

View File

@@ -58,7 +58,7 @@ public class LinkedIdWizard extends BaseActivity {
try {
Uri uri = getIntent().getData();
uri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(uri);
CachedPublicKeyRing ring = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(uri);
CachedPublicKeyRing ring = KeyRepository.create(this).getCachedPublicKeyRing(uri);
if (!ring.hasAnySecret()) {
Log.e(Constants.TAG, "Linked Identities can only be added to secret keys!");
finish();

View File

@@ -98,7 +98,7 @@ public abstract class PublicKeyRetrievalLoader extends AsyncTaskLoader<KeyRetrie
LocalKeyLookupLoader(Context context, List<byte[]> fingerprints) {
super(context, fingerprints);
this.keyRepository = KeyRepository.createDatabaseInteractor(context);
this.keyRepository = KeyRepository.create(context);
}
@Override

View File

@@ -96,7 +96,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
this.view = view;
this.loaderManager = loaderManager;
this.loaderId = loaderId;
this.databaseInteractor = KeyRepository.createDatabaseInteractor(context);
this.databaseInteractor = KeyRepository.create(context);
secretKeyAdapter = new TransferKeyAdapter(context, LayoutInflater.from(context), this);
view.setSecretKeyAdapter(secretKeyAdapter);

View File

@@ -136,7 +136,7 @@ public class BackupOperationTest {
@Before
public void setUp() {
KeyWritableRepository databaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
KeyWritableRepository.create(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream;
@@ -151,7 +151,7 @@ public class BackupOperationTest {
@Test
public void testExportAllLocalStripped() throws Exception {
BackupOperation op = new BackupOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
// make sure there is a local cert (so the later checks that there are none are meaningful)
assertTrue("second keyring has local certification", checkForLocal(mStaticRing2));
@@ -250,7 +250,7 @@ public class BackupOperationTest {
when(spyApplication.getContentResolver()).thenReturn(mockResolver);
BackupOperation op = new BackupOperation(spyApplication,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
BackupKeyringParcel parcel = BackupKeyringParcel.createBackupKeyringParcel(
new long[] { mStaticRing1.getMasterKeyId() }, false, false, true, fakeOutputUri);
@@ -307,7 +307,7 @@ public class BackupOperationTest {
{ // export encrypted
BackupOperation op = new BackupOperation(spyApplication,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
BackupKeyringParcel parcel = BackupKeyringParcel.createBackupKeyringParcel(
new long[] { mStaticRing1.getMasterKeyId() }, false, true, true, fakeOutputUri);
@@ -325,7 +325,7 @@ public class BackupOperationTest {
{
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
.setAllowSymmetricDecryption(true)

View File

@@ -47,7 +47,7 @@ public class BenchmarkOperationTest {
@Test
public void testBenchmark() throws Exception {
BenchmarkOperation op = new BenchmarkOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
op.execute(BenchmarkInputParcel.newInstance(), null);
}

View File

@@ -118,7 +118,7 @@ public class CertifyOperationTest {
@Before
public void setUp() throws Exception {
KeyWritableRepository databaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
KeyWritableRepository.create(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream;
@@ -133,7 +133,7 @@ public class CertifyOperationTest {
@Test
public void testSelfCertifyFlag() throws Exception {
CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
CanonicalizedPublicKeyRing ring = KeyWritableRepository.create(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing1.getMasterKeyId());
Assert.assertEquals("secret key must be marked self-certified in database",
// TODO this should be more correctly be VERIFIED_SELF at some point!
@@ -144,10 +144,10 @@ public class CertifyOperationTest {
@Test
public void testCertifyId() throws Exception {
CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
KeyWritableRepository.create(RuntimeEnvironment.application), null, null);
{
CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
CanonicalizedPublicKeyRing ring = KeyWritableRepository.create(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("public key must not be marked verified prior to certification",
Certs.UNVERIFIED, ring.getVerified());
@@ -161,7 +161,7 @@ public class CertifyOperationTest {
Assert.assertTrue("certification must succeed", result.success());
{
CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
CanonicalizedPublicKeyRing ring = KeyWritableRepository.create(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("new key must be verified now",
Certs.VERIFIED_SECRET, ring.getVerified());
@@ -172,10 +172,10 @@ public class CertifyOperationTest {
@Test
public void testCertifyAttribute() throws Exception {
CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
KeyWritableRepository.create(RuntimeEnvironment.application), null, null);
{
CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
CanonicalizedPublicKeyRing ring = KeyWritableRepository.create(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("public key must not be marked verified prior to certification",
Certs.UNVERIFIED, ring.getVerified());
@@ -189,7 +189,7 @@ public class CertifyOperationTest {
Assert.assertTrue("certification must succeed", result.success());
{
CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
CanonicalizedPublicKeyRing ring = KeyWritableRepository.create(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("new key must be verified now",
Certs.VERIFIED_SECRET, ring.getVerified());
@@ -201,7 +201,7 @@ public class CertifyOperationTest {
@Test
public void testCertifySelf() throws Exception {
CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
KeyWritableRepository.create(RuntimeEnvironment.application), null, null);
CertifyActionsParcel.Builder actions = CertifyActionsParcel.builder(mStaticRing1.getMasterKeyId());
actions.addAction(CertifyAction.createForUserIds(mStaticRing1.getMasterKeyId(),
@@ -218,7 +218,7 @@ public class CertifyOperationTest {
public void testCertifyNonexistent() throws Exception {
CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
KeyWritableRepository.create(RuntimeEnvironment.application), null, null);
{
CertifyActionsParcel.Builder actions = CertifyActionsParcel.builder(mStaticRing1.getMasterKeyId());

View File

@@ -92,7 +92,7 @@ public class PromoteKeyOperationTest {
@Before
public void setUp() throws Exception {
KeyWritableRepository databaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
KeyWritableRepository.create(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream;
@@ -106,7 +106,7 @@ public class PromoteKeyOperationTest {
@Test
public void testPromote() throws Exception {
PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
KeyWritableRepository.create(RuntimeEnvironment.application), null, null);
PromoteKeyResult result = op.execute(
PromoteKeyringParcel.createPromoteKeyringParcel(mStaticRing.getMasterKeyId(), null, null), null);
@@ -114,7 +114,7 @@ public class PromoteKeyOperationTest {
Assert.assertTrue("promotion must succeed", result.success());
{
CachedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
CachedPublicKeyRing ring = KeyWritableRepository.create(RuntimeEnvironment.application)
.getCachedPublicKeyRing(mStaticRing.getMasterKeyId());
Assert.assertTrue("key must have a secret now", ring.hasAnySecret());
@@ -131,7 +131,7 @@ public class PromoteKeyOperationTest {
@Test
public void testPromoteDivert() throws Exception {
PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
KeyWritableRepository.create(RuntimeEnvironment.application), null, null);
byte[] aid = Hex.decode("D2760001240102000000012345670000");
@@ -141,7 +141,7 @@ public class PromoteKeyOperationTest {
Assert.assertTrue("promotion must succeed", result.success());
{
CanonicalizedSecretKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
CanonicalizedSecretKeyRing ring = KeyWritableRepository.create(RuntimeEnvironment.application)
.getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
@@ -157,7 +157,7 @@ public class PromoteKeyOperationTest {
@Test
public void testPromoteDivertSpecific() throws Exception {
PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
KeyWritableRepository.create(RuntimeEnvironment.application), null, null);
byte[] aid = Hex.decode("D2760001240102000000012345670000");
@@ -171,7 +171,7 @@ public class PromoteKeyOperationTest {
Assert.assertTrue("promotion must succeed", result.success());
{
CanonicalizedSecretKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
CanonicalizedSecretKeyRing ring = KeyWritableRepository.create(RuntimeEnvironment.application)
.getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {

View File

@@ -126,7 +126,7 @@ public class InputDataOperationTest {
when(spyApplication.getContentResolver()).thenReturn(mockResolver);
InputDataOperation op = new InputDataOperation(spyApplication,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputDataParcel input = InputDataParcel.createInputDataParcel(fakeInputUri, null);
@@ -306,7 +306,7 @@ public class InputDataOperationTest {
when(spyApplication.getContentResolver()).thenReturn(mockResolver);
InputDataOperation op = new InputDataOperation(spyApplication,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputDataParcel input = InputDataParcel.createInputDataParcel(FAKE_CONTENT_INPUT_URI_1, null);
return op.execute(input, CryptoInputParcel.createCryptoInputParcel());

View File

@@ -149,7 +149,7 @@ public class PgpEncryptDecryptTest {
@Before
public void setUp() {
KeyWritableRepository databaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
KeyWritableRepository.create(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream;
@@ -173,7 +173,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available());
@@ -197,7 +197,7 @@ public class PgpEncryptDecryptTest {
InputData data = new InputData(in, in.available());
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
.setAllowSymmetricDecryption(true)
.build();
@@ -228,7 +228,7 @@ public class PgpEncryptDecryptTest {
InputData data = new InputData(in, in.available());
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
.setAllowSymmetricDecryption(true)
.build();
@@ -251,7 +251,7 @@ public class PgpEncryptDecryptTest {
InputData data = new InputData(in, in.available());
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
.setAllowSymmetricDecryption(true)
.build();
@@ -273,7 +273,7 @@ public class PgpEncryptDecryptTest {
InputData data = new InputData(in, in.available());
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
DecryptVerifyResult result = op.execute(input,
CryptoInputParcel.createCryptoInputParcel(), data, out);
@@ -299,7 +299,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available());
@@ -354,7 +354,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available());
@@ -415,7 +415,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available());
@@ -472,7 +472,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available());
@@ -574,7 +574,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available());
@@ -625,11 +625,11 @@ public class PgpEncryptDecryptTest {
CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
KeyWritableRepository databaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
KeyWritableRepository.create(RuntimeEnvironment.application);
databaseInteractor.saveSecretKeyRing(modified);
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
.setInputBytes(ciphertext)
.build();
@@ -650,11 +650,11 @@ public class PgpEncryptDecryptTest {
CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
KeyWritableRepository databaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
KeyWritableRepository.create(RuntimeEnvironment.application);
databaseInteractor.saveSecretKeyRing(modified);
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
.setInputBytes(ciphertext)
.build();
@@ -681,7 +681,7 @@ public class PgpEncryptDecryptTest {
CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
KeyWritableRepository databaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
KeyWritableRepository.create(RuntimeEnvironment.application);
databaseInteractor.saveSecretKeyRing(modified);
}
@@ -691,7 +691,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available());
@@ -735,7 +735,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available());
@@ -830,7 +830,7 @@ public class PgpEncryptDecryptTest {
{ // decryption with passphrase cached should succeed for the other key if first is gone
// delete first key from database
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete(
KeyWritableRepository.create(RuntimeEnvironment.application).getContentResolver().delete(
KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null
);
@@ -865,7 +865,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available());
@@ -911,7 +911,7 @@ public class PgpEncryptDecryptTest {
{ // decryption with passphrase cached should succeed for the other key if first is gone
// delete first key from database
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete(
KeyWritableRepository.create(RuntimeEnvironment.application).getContentResolver().delete(
KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null
);
@@ -950,7 +950,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaindata);
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
KeyWritableRepository.create(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available());
@@ -1068,7 +1068,7 @@ public class PgpEncryptDecryptTest {
final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) {
return new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null) {
KeyWritableRepository.create(RuntimeEnvironment.application), null) {
@Override
public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId)
throws NoSecretKeyException {

View File

@@ -68,7 +68,7 @@ public class EddsaTest {
@Before
public void setUp() throws Exception {
context = RuntimeEnvironment.application;
keyRepository = KeyWritableRepository.createDatabaseReadWriteInteractor(context);
keyRepository = KeyWritableRepository.create(context);
}

View File

@@ -35,7 +35,6 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.ProgressScaler;
import java.util.Arrays;
import java.util.Iterator;
@@ -44,7 +43,7 @@ import java.util.Iterator;
public class KeyRepositorySaveTest {
KeyWritableRepository mDatabaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
KeyWritableRepository.create(RuntimeEnvironment.application);
@BeforeClass
public static void setUpOnce() throws Exception {
@@ -62,17 +61,17 @@ public class KeyRepositorySaveTest {
SaveKeyringResult result;
// insert both keys, second should fail
result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first);
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(first);
Assert.assertTrue("first keyring import should succeed", result.success());
result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second);
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(second);
Assert.assertFalse("second keyring import should fail", result.success());
new KeychainDatabase(RuntimeEnvironment.application).clearDatabase();
// and the other way around
result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second);
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(second);
Assert.assertTrue("first keyring import should succeed", result.success());
result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first);
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(first);
Assert.assertFalse("second keyring import should fail", result.success());
}
@@ -91,14 +90,14 @@ public class KeyRepositorySaveTest {
SaveKeyringResult result;
// insert secret, this should fail because of missing self-cert
result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
result = KeyWritableRepository.create(RuntimeEnvironment.application)
.saveSecretKeyRing(seckey);
Assert.assertFalse("secret keyring import before pubring import should fail", result.success());
// insert pubkey, then seckey - both should succeed
result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(pubkey);
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(pubkey);
Assert.assertTrue("public keyring import should succeed", result.success());
result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
result = KeyWritableRepository.create(RuntimeEnvironment.application)
.saveSecretKeyRing(seckey);
Assert.assertTrue("secret keyring import after pubring import should succeed", result.success());

View File

@@ -52,7 +52,7 @@ public class KeychainExternalProviderTest {
KeyWritableRepository databaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
KeyWritableRepository.create(RuntimeEnvironment.application);
ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver();
ApiPermissionHelper apiPermissionHelper;
ApiDataAccessObject apiDao;

View File

@@ -52,7 +52,7 @@ public class KeyringTestingHelper {
public boolean addKeyring(Collection<String> blobFiles) throws Exception {
KeyWritableRepository databaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(context);
KeyWritableRepository.create(context);
byte[] data = TestDataUtil.readAllFully(blobFiles);
UncachedKeyRing ring = UncachedKeyRing.decodeFromData(data);