aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java48
1 files changed, 29 insertions, 19 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
index f6db3f9b2..061f91176 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
@@ -41,6 +41,16 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+/**
+ * SQLite Datatypes (from http://www.sqlite.org/datatype3.html)
+ * - NULL. The value is a NULL value.
+ * - INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
+ * - REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number.
+ * - TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).
+ * - BLOB. The value is a blob of data, stored exactly as it was input.
+ *
+ * Adding BOOLEAN results in an INTEGER, but we keep BOOLEAN to indicate the usage!
+ */
public class KeychainDatabase extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "openkeychain.db";
private static final int DATABASE_VERSION = 2;
@@ -97,7 +107,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
private static final String CREATE_USER_IDS =
"CREATE TABLE IF NOT EXISTS " + Tables.USER_IDS + "("
+ UserIdsColumns.MASTER_KEY_ID + " INTEGER, "
- + UserIdsColumns.USER_ID + " CHARMANDER, "
+ + UserIdsColumns.USER_ID + " TEXT, "
+ UserIdsColumns.IS_PRIMARY + " BOOLEAN, "
+ UserIdsColumns.IS_REVOKED + " BOOLEAN, "
@@ -140,7 +150,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
"CREATE TABLE IF NOT EXISTS " + Tables.API_ACCOUNTS + " ("
+ BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ ApiAppsAccountsColumns.ACCOUNT_NAME + " TEXT NOT NULL, "
- + ApiAppsAccountsColumns.KEY_ID + " INT64, "
+ + ApiAppsAccountsColumns.KEY_ID + " INTEGER, "
+ ApiAppsAccountsColumns.ENCRYPTION_ALGORITHM + " INTEGER, "
+ ApiAppsAccountsColumns.HASH_ALORITHM + " INTEGER, "
+ ApiAppsAccountsColumns.COMPRESSION + " INTEGER, "
@@ -214,10 +224,10 @@ public class KeychainDatabase extends SQLiteOpenHelper {
{
// It's the Java way =(
String[] dbs = context.databaseList();
- for(String db : dbs) {
- if(db.equals("apg.db")) {
+ for (String db : dbs) {
+ if (db.equals("apg.db")) {
hasApgDb = true;
- } else if(db.equals("apg_old.db")) {
+ } else if (db.equals("apg_old.db")) {
Log.d(Constants.TAG, "Found apg_old.db");
}
}
@@ -252,14 +262,14 @@ public class KeychainDatabase extends SQLiteOpenHelper {
+ " SELECT 1 FROM key_rings d2 WHERE key_rings.master_key_id = d2.master_key_id"
+ " AND d2.type = 1) ORDER BY type ASC", null);
Log.d(Constants.TAG, "Importing " + c.getCount() + " secret keyrings from apg.db...");
- for(int i = 0; i < c.getCount(); i++) {
+ for (int i = 0; i < c.getCount(); i++) {
c.moveToPosition(i);
byte[] data = c.getBlob(0);
PGPKeyRing ring = PgpConversionHelper.BytesToPGPKeyRing(data);
ProviderHelper providerHelper = new ProviderHelper(context);
- if(ring instanceof PGPPublicKeyRing)
+ if (ring instanceof PGPPublicKeyRing)
providerHelper.saveKeyRing((PGPPublicKeyRing) ring);
- else if(ring instanceof PGPSecretKeyRing)
+ else if (ring instanceof PGPSecretKeyRing)
providerHelper.saveKeyRing((PGPSecretKeyRing) ring);
else {
Log.e(Constants.TAG, "Unknown blob data type!");
@@ -274,14 +284,14 @@ public class KeychainDatabase extends SQLiteOpenHelper {
+ " d2.type = 1)) DESC, type DESC", null);
// import from old database
Log.d(Constants.TAG, "Importing " + c.getCount() + " keyrings from apg.db...");
- for(int i = 0; i < c.getCount(); i++) {
+ for (int i = 0; i < c.getCount(); i++) {
c.moveToPosition(i);
byte[] data = c.getBlob(0);
PGPKeyRing ring = PgpConversionHelper.BytesToPGPKeyRing(data);
ProviderHelper providerHelper = new ProviderHelper(context);
if (ring instanceof PGPPublicKeyRing) {
providerHelper.saveKeyRing((PGPPublicKeyRing) ring);
- } else if(ring instanceof PGPSecretKeyRing) {
+ } else if (ring instanceof PGPSecretKeyRing) {
providerHelper.saveKeyRing((PGPSecretKeyRing) ring);
} else {
Log.e(Constants.TAG, "Unknown blob data type!");
@@ -290,10 +300,10 @@ public class KeychainDatabase extends SQLiteOpenHelper {
} catch (IOException e) {
Log.e(Constants.TAG, "Error importing apg.db!", e);
} finally {
- if(c != null) {
+ if (c != null) {
c.close();
}
- if(db != null) {
+ if (db != null) {
db.close();
}
}
@@ -307,37 +317,37 @@ public class KeychainDatabase extends SQLiteOpenHelper {
FileInputStream ss = new FileInputStream(in);
FileOutputStream ds = new FileOutputStream(out);
byte[] buf = new byte[512];
- while(ss.available() > 0) {
+ while (ss.available() > 0) {
int count = ss.read(buf, 0, 512);
ds.write(buf, 0, count);
}
}
public static void debugRead(Context context) throws IOException {
- if(!Constants.DEBUG) {
+ if (!Constants.DEBUG) {
return;
}
File in = context.getDatabasePath("debug.db");
File out = context.getDatabasePath("openkeychain.db");
- if(!in.canRead()) {
+ if (!in.canRead()) {
throw new IOException("Cannot read " + in.getName());
}
- if(!out.canRead()) {
+ if (!out.canRead()) {
throw new IOException("Cannot write " + out.getName());
}
copy(in, out);
}
public static void debugWrite(Context context) throws IOException {
- if(!Constants.DEBUG) {
+ if (!Constants.DEBUG) {
return;
}
File in = context.getDatabasePath("openkeychain.db");
File out = context.getDatabasePath("debug.db");
- if(!in.canRead()) {
+ if (!in.canRead()) {
throw new IOException("Cannot read " + in.getName());
}
- if(!out.canRead()) {
+ if (!out.canRead()) {
throw new IOException("Cannot write " + out.getName());
}
copy(in, out);