Search in sources :

Example 1 with PwDatabaseV4

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();
}
Also used : Context(android.content.Context) PwDbV4Output(com.keepassdroid.database.save.PwDbV4Output) AssetManager(android.content.res.AssetManager) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CopyInputStream(com.keepassdroid.stream.CopyInputStream) InputStream(java.io.InputStream) ImporterV4(com.keepassdroid.database.load.ImporterV4) FileOutputStream(java.io.FileOutputStream) CopyInputStream(com.keepassdroid.stream.CopyInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PwDatabaseV4(com.keepassdroid.database.PwDatabaseV4)

Example 2 with PwDatabaseV4

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;
}
Also used : PwDatabaseV3(com.keepassdroid.database.PwDatabaseV3) Locale(java.util.Locale) PwGroupV3(com.keepassdroid.database.PwGroupV3) PwGroupV4(com.keepassdroid.database.PwGroupV4) PwDatabase(com.keepassdroid.database.PwDatabase) PwEntry(com.keepassdroid.database.PwEntry) PwGroup(com.keepassdroid.database.PwGroup) LinkedList(java.util.LinkedList) PwDatabaseV4(com.keepassdroid.database.PwDatabaseV4)

Example 3 with PwDatabaseV4

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());
}
Also used : PwEntryV4(com.keepassdroid.database.PwEntryV4) PwDatabaseV4(com.keepassdroid.database.PwDatabaseV4)

Example 4 with PwDatabaseV4

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();
}
Also used : Context(android.content.Context) AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) ImporterV4(com.keepassdroid.database.load.ImporterV4) PwDatabaseV4(com.keepassdroid.database.PwDatabaseV4)

Aggregations

PwDatabaseV4 (com.keepassdroid.database.PwDatabaseV4)4 Context (android.content.Context)2 AssetManager (android.content.res.AssetManager)2 ImporterV4 (com.keepassdroid.database.load.ImporterV4)2 InputStream (java.io.InputStream)2 PwDatabase (com.keepassdroid.database.PwDatabase)1 PwDatabaseV3 (com.keepassdroid.database.PwDatabaseV3)1 PwEntry (com.keepassdroid.database.PwEntry)1 PwEntryV4 (com.keepassdroid.database.PwEntryV4)1 PwGroup (com.keepassdroid.database.PwGroup)1 PwGroupV3 (com.keepassdroid.database.PwGroupV3)1 PwGroupV4 (com.keepassdroid.database.PwGroupV4)1 PwDbV4Output (com.keepassdroid.database.save.PwDbV4Output)1 CopyInputStream (com.keepassdroid.stream.CopyInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 LinkedList (java.util.LinkedList)1 Locale (java.util.Locale)1