From 36cc814e84135296fc14d383e61e6b4fe8dfe269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Tue, 18 Jun 2013 01:48:25 +0200 Subject: [PATCH] Add database columns for crypto consumer preferences --- .../keychain/provider/KeychainContract.java | 13 ++++++++++++- .../keychain/provider/KeychainDatabase.java | 6 +++++- .../keychain/provider/KeychainProvider.java | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainContract.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainContract.java index 776d1bfb9..985498e3a 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainContract.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainContract.java @@ -43,7 +43,7 @@ public class KeychainContract { String CREATION = "creation"; String EXPIRY = "expiry"; String KEY_RING_ROW_ID = "key_ring_row_id"; // foreign key to key_rings._ID - String KEY_DATA = "key_data"; // PGPPublicKey / PGPSecretKey blob + String KEY_DATA = "key_data"; // PGPPublicKey/PGPSecretKey blob String RANK = "rank"; } @@ -55,6 +55,11 @@ public class KeychainContract { interface CryptoConsumersColumns { String PACKAGE_NAME = "package_name"; + String PRIVATE_KEY_ID = "private_key_id"; // not a database id + String ASCII_ARMOR = "ascii_armor"; + String ENCRYPTION_ALGORITHM = "encryption_algorithm"; + String HASH_ALORITHM = "hash_algorithm"; + String COMPRESSION = "compression"; } public static final class KeyTypes { @@ -83,6 +88,7 @@ public class KeychainContract { public static final String PATH_KEYS = "keys"; public static final String BASE_CRYPTO_CONSUMERS = "crypto_consumers"; + public static final String PATH_BY_PACKAGE_NAME = "package_name"; public static class KeyRings implements KeyRingsColumns, BaseColumns { public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon() @@ -226,6 +232,11 @@ public class KeychainContract { public static Uri buildIdUri(String rowId) { return CONTENT_URI.buildUpon().appendPath(rowId).build(); } + + public static Uri buildByPackageNameUri(String packageName) { + return CONTENT_URI.buildUpon().appendPath(PATH_BY_PACKAGE_NAME).appendPath(packageName) + .build(); + } } public static class DataStream { diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainDatabase.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainDatabase.java index f30292b52..6f31f4945 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainDatabase.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainDatabase.java @@ -67,7 +67,11 @@ public class KeychainDatabase extends SQLiteOpenHelper { private static final String CREATE_CRYPTO_CONSUMERS = "CREATE TABLE IF NOT EXISTS " + Tables.CRYPTO_CONSUMERS + " (" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + CryptoConsumersColumns.PACKAGE_NAME - + " TEXT UNIQUE)"; + + " TEXT UNIQUE, " + CryptoConsumersColumns.PRIVATE_KEY_ID + " INT64, " + + CryptoConsumersColumns.ASCII_ARMOR + " INTEGER, " + + CryptoConsumersColumns.ENCRYPTION_ALGORITHM + " INTEGER, " + + CryptoConsumersColumns.HASH_ALORITHM + " INTEGER, " + + CryptoConsumersColumns.COMPRESSION + " INTEGER)"; KeychainDatabase(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainProvider.java index a34cda0c3..5a86b0bdb 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -80,6 +80,7 @@ public class KeychainProvider extends ContentProvider { private static final int CRYPTO_CONSUMERS = 301; private static final int CRYPTO_CONSUMERS_BY_ROW_ID = 302; + private static final int CRYPTO_CONSUMERS_BY_PACKAGE_NAME = 303; // private static final int DATA_STREAM = 401; @@ -230,6 +231,8 @@ public class KeychainProvider extends ContentProvider { matcher.addURI(authority, KeychainContract.BASE_CRYPTO_CONSUMERS, CRYPTO_CONSUMERS); matcher.addURI(authority, KeychainContract.BASE_CRYPTO_CONSUMERS + "/#", CRYPTO_CONSUMERS_BY_ROW_ID); + matcher.addURI(authority, KeychainContract.BASE_CRYPTO_CONSUMERS + "/" + + KeychainContract.PATH_BY_PACKAGE_NAME + "/*", CRYPTO_CONSUMERS_BY_PACKAGE_NAME); /** * data stream @@ -294,6 +297,7 @@ public class KeychainProvider extends ContentProvider { return CryptoConsumers.CONTENT_TYPE; case CRYPTO_CONSUMERS_BY_ROW_ID: + case CRYPTO_CONSUMERS_BY_PACKAGE_NAME: return CryptoConsumers.CONTENT_ITEM_TYPE; default: @@ -607,6 +611,12 @@ public class KeychainProvider extends ContentProvider { case CRYPTO_CONSUMERS: qb.setTables(Tables.CRYPTO_CONSUMERS); + break; + case CRYPTO_CONSUMERS_BY_PACKAGE_NAME: + qb.setTables(Tables.CRYPTO_CONSUMERS); + qb.appendWhere(CryptoConsumers.PACKAGE_NAME + " = "); + qb.appendWhereEscapeString(uri.getPathSegments().get(2)); + break; default: @@ -755,6 +765,7 @@ public class KeychainProvider extends ContentProvider { selectionArgs); break; case CRYPTO_CONSUMERS_BY_ROW_ID: + case CRYPTO_CONSUMERS_BY_PACKAGE_NAME: count = db.delete(Tables.CRYPTO_CONSUMERS, buildDefaultCryptoConsumersSelection(uri, selection), selectionArgs); break; @@ -818,6 +829,11 @@ public class KeychainProvider extends ContentProvider { count = db.update(Tables.USER_IDS, values, buildDefaultUserIdsSelection(uri, selection), selectionArgs); break; + case CRYPTO_CONSUMERS_BY_ROW_ID: + case CRYPTO_CONSUMERS_BY_PACKAGE_NAME: + count = db.update(Tables.CRYPTO_CONSUMERS, values, + buildDefaultCryptoConsumersSelection(uri, selection), selectionArgs); + break; default: throw new UnsupportedOperationException("Unknown uri: " + uri); }