Formatting KeychainDatabase
This commit is contained in:
@@ -224,10 +224,10 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
|||||||
{
|
{
|
||||||
// It's the Java way =(
|
// It's the Java way =(
|
||||||
String[] dbs = context.databaseList();
|
String[] dbs = context.databaseList();
|
||||||
for(String db : dbs) {
|
for (String db : dbs) {
|
||||||
if(db.equals("apg.db")) {
|
if (db.equals("apg.db")) {
|
||||||
hasApgDb = true;
|
hasApgDb = true;
|
||||||
} else if(db.equals("apg_old.db")) {
|
} else if (db.equals("apg_old.db")) {
|
||||||
Log.d(Constants.TAG, "Found apg_old.db");
|
Log.d(Constants.TAG, "Found apg_old.db");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,14 +262,14 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
|||||||
+ " SELECT 1 FROM key_rings d2 WHERE key_rings.master_key_id = d2.master_key_id"
|
+ " 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);
|
+ " AND d2.type = 1) ORDER BY type ASC", null);
|
||||||
Log.d(Constants.TAG, "Importing " + c.getCount() + " secret keyrings from apg.db...");
|
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);
|
c.moveToPosition(i);
|
||||||
byte[] data = c.getBlob(0);
|
byte[] data = c.getBlob(0);
|
||||||
PGPKeyRing ring = PgpConversionHelper.BytesToPGPKeyRing(data);
|
PGPKeyRing ring = PgpConversionHelper.BytesToPGPKeyRing(data);
|
||||||
ProviderHelper providerHelper = new ProviderHelper(context);
|
ProviderHelper providerHelper = new ProviderHelper(context);
|
||||||
if(ring instanceof PGPPublicKeyRing)
|
if (ring instanceof PGPPublicKeyRing)
|
||||||
providerHelper.saveKeyRing((PGPPublicKeyRing) ring);
|
providerHelper.saveKeyRing((PGPPublicKeyRing) ring);
|
||||||
else if(ring instanceof PGPSecretKeyRing)
|
else if (ring instanceof PGPSecretKeyRing)
|
||||||
providerHelper.saveKeyRing((PGPSecretKeyRing) ring);
|
providerHelper.saveKeyRing((PGPSecretKeyRing) ring);
|
||||||
else {
|
else {
|
||||||
Log.e(Constants.TAG, "Unknown blob data type!");
|
Log.e(Constants.TAG, "Unknown blob data type!");
|
||||||
@@ -284,14 +284,14 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
|||||||
+ " d2.type = 1)) DESC, type DESC", null);
|
+ " d2.type = 1)) DESC, type DESC", null);
|
||||||
// import from old database
|
// import from old database
|
||||||
Log.d(Constants.TAG, "Importing " + c.getCount() + " keyrings from apg.db...");
|
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);
|
c.moveToPosition(i);
|
||||||
byte[] data = c.getBlob(0);
|
byte[] data = c.getBlob(0);
|
||||||
PGPKeyRing ring = PgpConversionHelper.BytesToPGPKeyRing(data);
|
PGPKeyRing ring = PgpConversionHelper.BytesToPGPKeyRing(data);
|
||||||
ProviderHelper providerHelper = new ProviderHelper(context);
|
ProviderHelper providerHelper = new ProviderHelper(context);
|
||||||
if (ring instanceof PGPPublicKeyRing) {
|
if (ring instanceof PGPPublicKeyRing) {
|
||||||
providerHelper.saveKeyRing((PGPPublicKeyRing) ring);
|
providerHelper.saveKeyRing((PGPPublicKeyRing) ring);
|
||||||
} else if(ring instanceof PGPSecretKeyRing) {
|
} else if (ring instanceof PGPSecretKeyRing) {
|
||||||
providerHelper.saveKeyRing((PGPSecretKeyRing) ring);
|
providerHelper.saveKeyRing((PGPSecretKeyRing) ring);
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG, "Unknown blob data type!");
|
Log.e(Constants.TAG, "Unknown blob data type!");
|
||||||
@@ -300,10 +300,10 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, "Error importing apg.db!", e);
|
Log.e(Constants.TAG, "Error importing apg.db!", e);
|
||||||
} finally {
|
} finally {
|
||||||
if(c != null) {
|
if (c != null) {
|
||||||
c.close();
|
c.close();
|
||||||
}
|
}
|
||||||
if(db != null) {
|
if (db != null) {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -317,37 +317,37 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
|||||||
FileInputStream ss = new FileInputStream(in);
|
FileInputStream ss = new FileInputStream(in);
|
||||||
FileOutputStream ds = new FileOutputStream(out);
|
FileOutputStream ds = new FileOutputStream(out);
|
||||||
byte[] buf = new byte[512];
|
byte[] buf = new byte[512];
|
||||||
while(ss.available() > 0) {
|
while (ss.available() > 0) {
|
||||||
int count = ss.read(buf, 0, 512);
|
int count = ss.read(buf, 0, 512);
|
||||||
ds.write(buf, 0, count);
|
ds.write(buf, 0, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debugRead(Context context) throws IOException {
|
public static void debugRead(Context context) throws IOException {
|
||||||
if(!Constants.DEBUG) {
|
if (!Constants.DEBUG) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File in = context.getDatabasePath("debug.db");
|
File in = context.getDatabasePath("debug.db");
|
||||||
File out = context.getDatabasePath("openkeychain.db");
|
File out = context.getDatabasePath("openkeychain.db");
|
||||||
if(!in.canRead()) {
|
if (!in.canRead()) {
|
||||||
throw new IOException("Cannot read " + in.getName());
|
throw new IOException("Cannot read " + in.getName());
|
||||||
}
|
}
|
||||||
if(!out.canRead()) {
|
if (!out.canRead()) {
|
||||||
throw new IOException("Cannot write " + out.getName());
|
throw new IOException("Cannot write " + out.getName());
|
||||||
}
|
}
|
||||||
copy(in, out);
|
copy(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debugWrite(Context context) throws IOException {
|
public static void debugWrite(Context context) throws IOException {
|
||||||
if(!Constants.DEBUG) {
|
if (!Constants.DEBUG) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File in = context.getDatabasePath("openkeychain.db");
|
File in = context.getDatabasePath("openkeychain.db");
|
||||||
File out = context.getDatabasePath("debug.db");
|
File out = context.getDatabasePath("debug.db");
|
||||||
if(!in.canRead()) {
|
if (!in.canRead()) {
|
||||||
throw new IOException("Cannot read " + in.getName());
|
throw new IOException("Cannot read " + in.getName());
|
||||||
}
|
}
|
||||||
if(!out.canRead()) {
|
if (!out.canRead()) {
|
||||||
throw new IOException("Cannot write " + out.getName());
|
throw new IOException("Cannot write " + out.getName());
|
||||||
}
|
}
|
||||||
copy(in, out);
|
copy(in, out);
|
||||||
|
|||||||
Reference in New Issue
Block a user