use of com.keepassdroid.database.PwDatabaseV4 in project KeePassDX by Kunzisoft.
the class Kdb4 method testSaving.
private void testSaving(String inputFile, String password, String outputFile) throws IOException, InvalidDBException, PwDbOutputException {
Context ctx = getContext();
AssetManager am = ctx.getAssets();
InputStream is = am.open(inputFile, AssetManager.ACCESS_STREAMING);
ImporterV4 importer = new ImporterV4();
PwDatabaseV4 db = importer.openDatabase(is, password, null);
is.close();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PwDbV4Output output = (PwDbV4Output) PwDbOutput.getInstance(db, bos);
output.output();
byte[] data = bos.toByteArray();
FileOutputStream fos = new FileOutputStream(TestUtil.getSdPath(outputFile), false);
InputStream bis = new ByteArrayInputStream(data);
bis = new CopyInputStream(bis, fos);
importer = new ImporterV4();
db = importer.openDatabase(bis, password, null);
bis.close();
fos.close();
}
use of com.keepassdroid.database.PwDatabaseV4 in project KeePassDX by Kunzisoft.
the class SearchDbHelper method search.
public PwGroup search(Database db, String qStr) {
PwDatabase pm = db.pm;
PwGroup group;
if (pm instanceof PwDatabaseV3) {
group = new PwGroupV3();
} else if (pm instanceof PwDatabaseV4) {
group = new PwGroupV4();
} else {
Log.d("SearchDbHelper", "Tried to search with unknown db");
return null;
}
group.setName(mCtx.getString(R.string.search_results));
group.setEntries(new ArrayList<>());
// Search all entries
Locale loc = Locale.getDefault();
qStr = qStr.toLowerCase(loc);
boolean isOmitBackup = omitBackup();
Queue<PwGroup> worklist = new LinkedList<PwGroup>();
if (pm.rootGroup != null) {
worklist.add(pm.rootGroup);
}
while (worklist.size() != 0) {
PwGroup top = worklist.remove();
if (pm.isGroupSearchable(top, isOmitBackup)) {
for (PwEntry entry : top.getChildEntries()) {
processEntries(entry, group.getChildEntries(), qStr, loc);
}
for (PwGroup childGroup : top.getChildGroups()) {
if (childGroup != null) {
worklist.add(childGroup);
}
}
}
}
return group;
}
use of com.keepassdroid.database.PwDatabaseV4 in project KeePassDX by Kunzisoft.
the class EntryV4 method testBackup.
public void testBackup() {
PwDatabaseV4 db = new PwDatabaseV4();
db.historyMaxItems = 2;
PwEntryV4 entry = new PwEntryV4();
entry.startToDecodeReference(db);
entry.setTitle("Title1");
entry.setUsername("User1");
entry.createBackup(db);
entry.setTitle("Title2");
entry.setUsername("User2");
entry.createBackup(db);
entry.setTitle("Title3");
entry.setUsername("User3");
entry.createBackup(db);
PwEntryV4 backup = entry.getHistory().get(0);
entry.endToDecodeReference(db);
assertEquals("Title2", backup.getTitle());
assertEquals("User2", backup.getUsername());
}
use of com.keepassdroid.database.PwDatabaseV4 in project KeePassDX by Kunzisoft.
the class Kdb4Header method testReadHeader.
public void testReadHeader() throws Exception {
Context ctx = getContext();
AssetManager am = ctx.getAssets();
InputStream is = am.open("test.kdbx", AssetManager.ACCESS_STREAMING);
ImporterV4 importer = new ImporterV4();
PwDatabaseV4 db = importer.openDatabase(is, "12345", null);
assertEquals(6000, db.numKeyEncRounds);
assertTrue(db.dataCipher.equals(AesEngine.CIPHER_UUID));
is.close();
}
Aggregations