}
return version;
}
-
-////////// Salt Functions ////////////////
- /**
- * Store the salt
- *
- * @return String version of salt
- */
- public String fetchSalt() {
- String salt="";
+////////// Single value accessor Functions ////////////////
+
+ private String fetchSV(String table, String key) {
+ String res="";
try {
- Cursor c = db.query(true, TABLE_SALT, new String[] {"salt"},
+ Cursor c = db.query(true, table, new String[] {key},
null, null, null, null, null,null);
if(c.getCount() > 0) {
c.moveToFirst();
- salt=c.getString(0);
+ res=c.getString(0);
}
c.close();
} catch (SQLException e)
{
Log.d(TAG,"SQLite exception: " + e.getLocalizedMessage());
}
- return salt;
+ return res;
}
- /**
- * Store the salt into the database.
- *
- * @param salt String version of the salt
- */
- public void storeSalt(String salt) {
+ public void storeSV(String table, String key, String value) {
ContentValues args = new ContentValues();
try {
- db.delete(TABLE_SALT, "1=1", null);
- args.put("salt", salt);
- db.insert(TABLE_SALT, null, args);
+ db.delete(table, "1=1", null);
+ args.put(key, value);
+ db.insert(table, null, args);
} catch (SQLException e)
{
Log.d(TAG,"SQLite exception: " + e.getLocalizedMessage());
}
}
+////////// Salt Functions ////////////////
+
+ /**
+ * Store the salt
+ *
+ * @return String version of salt
+ */
+ public String fetchSalt() {
+ return fetchSV(TABLE_SALT, "salt");
+ }
+
+ /**
+ * Store the salt into the database.
+ *
+ * @param salt String version of the salt
+ */
+ public void storeSalt(String salt) {
+ storeSV(TABLE_SALT, "salt", salt);
+ }
+
////////// Master Key Functions ////////////////
/**
* @return
*/
public String fetchMasterKey() {
- String key="";
- try {
- Cursor c = db.query(true, TABLE_MASTER_KEY, new String[] {"encryptedkey"},
- null, null, null, null, null,null);
- if(c.getCount() > 0) {
- c.moveToFirst();
- key=c.getString(0);
- }
- c.close();
- } catch (SQLException e)
- {
- Log.d(TAG,"SQLite exception: " + e.getLocalizedMessage());
- }
- return key;
+ return fetchSV(TABLE_MASTER_KEY, "encryptedkey");
}
/**
* @param PBEKey
*/
public void storeMasterKey(String MasterKey) {
- ContentValues args = new ContentValues();
- try {
- db.delete(TABLE_MASTER_KEY, "1=1", null);
- args.put("encryptedkey", MasterKey);
- db.insert(TABLE_MASTER_KEY, null, args);
- } catch (SQLException e)
- {
- Log.d(TAG,"SQLite exception: " + e.getLocalizedMessage());
- }
+ storeSV(TABLE_MASTER_KEY, "encryptedkey", MasterKey);
}
+
//////////Category Functions ////////////////
/**