mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-06 17:25:05 -05:00
certs: close in from both sides :)
This commit is contained in:
parent
535f2caf2c
commit
74f8ec0365
@ -20,6 +20,8 @@ package org.sufficientlysecure.keychain.provider;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Date;
|
||||
|
||||
import org.spongycastle.bcpg.ArmoredOutputStream;
|
||||
@ -59,25 +61,30 @@ public class ProviderHelper {
|
||||
/**
|
||||
* Private helper method to get PGPKeyRing from database
|
||||
*/
|
||||
public static PGPKeyRing getPGPKeyRing(Context context, Uri queryUri) {
|
||||
public static Map<Long, PGPKeyRing> getPGPKeyRings(Context context, Uri queryUri) {
|
||||
Cursor cursor = context.getContentResolver().query(queryUri,
|
||||
new String[]{KeyRings._ID, KeyRings.KEY_RING_DATA}, null, null, null);
|
||||
new String[]{KeyRings._ID, KeyRings.MASTER_KEY_ID, KeyRings.KEY_RING_DATA}, null, null, null);
|
||||
|
||||
PGPKeyRing keyRing = null;
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
Map<Long, PGPKeyRing> result = new HashMap<Long, PGPKeyRing>(cursor.getCount());
|
||||
if (cursor != null && cursor.moveToFirst()) do {
|
||||
int keyRingDataCol = cursor.getColumnIndex(KeyRings.KEY_RING_DATA);
|
||||
int masterKeyIdCol = cursor.getColumnIndex(KeyRings.MASTER_KEY_ID);
|
||||
|
||||
byte[] data = cursor.getBlob(keyRingDataCol);
|
||||
if (data != null) {
|
||||
keyRing = PgpConversionHelper.BytesToPGPKeyRing(data);
|
||||
}
|
||||
result.put(cursor.getLong(masterKeyIdCol), PgpConversionHelper.BytesToPGPKeyRing(data));
|
||||
}
|
||||
|
||||
} while(cursor.moveToNext());
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return keyRing;
|
||||
return result;
|
||||
}
|
||||
public static PGPKeyRing getPGPKeyRing(Context context, Uri queryUri) {
|
||||
return getPGPKeyRings(context, queryUri).values().iterator().next();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -321,6 +328,30 @@ public class ProviderHelper {
|
||||
return ContentProviderOperation.newInsert(uri).withValues(values).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing
|
||||
*/
|
||||
private static ContentProviderOperation buildPublicCertOperations(Context context,
|
||||
long keyRingRowId,
|
||||
int rank,
|
||||
long keyId,
|
||||
PGPSignature cert,
|
||||
boolean verified)
|
||||
throws IOException {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Certs.KEY_RING_ROW_ID, keyRingRowId);
|
||||
values.put(Certs.RANK, rank);
|
||||
values.put(Certs.KEY_ID, keyId);
|
||||
values.put(Certs.KEY_ID_CERTIFIER, cert.getKeyID());
|
||||
values.put(Certs.CREATION, cert.getCreationTime().getTime() / 1000);
|
||||
values.put(Certs.VERIFIED, verified);
|
||||
values.put(Certs.KEY_DATA, cert.getEncoded());
|
||||
|
||||
Uri uri = Certs.buildCertsUri(Long.toString(keyRingRowId));
|
||||
|
||||
return ContentProviderOperation.newInsert(uri).withValues(values).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build ContentProviderOperation to add PublicUserIds to database corresponding to a keyRing
|
||||
*/
|
||||
|
@ -280,7 +280,9 @@ public class KeyListFragment extends Fragment implements AdapterView.OnItemClick
|
||||
} else {
|
||||
viewIntent = new Intent(getActivity(), ViewKeyActivityJB.class);
|
||||
}
|
||||
viewIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsByMasterKeyIdUri(Long.toString(mAdapter.getMasterKeyId(position))));
|
||||
viewIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsByMasterKeyIdUri(
|
||||
Long.toString(mAdapter.getMasterKeyId(position)))
|
||||
);
|
||||
startActivity(viewIntent);
|
||||
}
|
||||
|
||||
@ -379,8 +381,8 @@ public class KeyListFragment extends Fragment implements AdapterView.OnItemClick
|
||||
/**
|
||||
* Bind cursor data to the item list view
|
||||
* <p/>
|
||||
* NOTE: CursorAdapter already implements the ViewHolder pattern in its getView() method. Thus
|
||||
* no ViewHolder is required here.
|
||||
* NOTE: CursorAdapter already implements the ViewHolder pattern in its getView() method.
|
||||
* Thus no ViewHolder is required here.
|
||||
*/
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
@ -417,7 +419,11 @@ public class KeyListFragment extends Fragment implements AdapterView.OnItemClick
|
||||
button.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
Intent editIntent = new Intent(getActivity(), EditKeyActivity.class);
|
||||
editIntent.setData(KeychainContract.KeyRings.buildSecretKeyRingsByMasterKeyIdUri(Long.toString(id)));
|
||||
editIntent.setData(
|
||||
KeychainContract.KeyRings.buildSecretKeyRingsByMasterKeyIdUri(
|
||||
Long.toString(id)
|
||||
)
|
||||
);
|
||||
editIntent.setAction(EditKeyActivity.ACTION_EDIT_KEY);
|
||||
startActivityForResult(editIntent, 0);
|
||||
}
|
||||
@ -504,7 +510,7 @@ public class KeyListFragment extends Fragment implements AdapterView.OnItemClick
|
||||
String userId = mCursor.getString(KeyListFragment.INDEX_UID);
|
||||
String headerText = convertView.getResources().getString(R.string.user_id_no_name);
|
||||
if (userId != null && userId.length() > 0) {
|
||||
headerText = "" + mCursor.getString(KeyListFragment.INDEX_UID).subSequence(0, 1).charAt(0);
|
||||
headerText = "" + userId.subSequence(0, 1).charAt(0);
|
||||
}
|
||||
holder.text.setText(headerText);
|
||||
holder.count.setVisibility(View.GONE);
|
||||
|
Loading…
Reference in New Issue
Block a user