Search in sources :

Example 1 with PwDbV3OutputDebug

use of com.keepassdroid.database.save.PwDbV3OutputDebug in project KeePassDX by Kunzisoft.

the class PwManagerOutputTest method testHeader.

public void testHeader() throws PwDbOutputException, IOException {
    ByteArrayOutputStream bActual = new ByteArrayOutputStream();
    PwDbV3Output pActual = new PwDbV3OutputDebug(mPM, bActual, true);
    PwDbHeaderV3 header = pActual.outputHeader(bActual);
    ByteArrayOutputStream bExpected = new ByteArrayOutputStream();
    PwDbHeaderOutputV3 outExpected = new PwDbHeaderOutputV3(mPM.dbHeader, bExpected);
    outExpected.output();
    assertHeadersEquals(mPM.dbHeader, header);
    assertTrue("No output", bActual.toByteArray().length > 0);
    assertArrayEquals("Header does not match.", bExpected.toByteArray(), bActual.toByteArray());
}
Also used : PwDbV3Output(com.keepassdroid.database.save.PwDbV3Output) PwDbHeaderV3(com.keepassdroid.database.PwDbHeaderV3) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PwDbV3OutputDebug(com.keepassdroid.database.save.PwDbV3OutputDebug) PwDbHeaderOutputV3(com.keepassdroid.database.save.PwDbHeaderOutputV3)

Example 2 with PwDbV3OutputDebug

use of com.keepassdroid.database.save.PwDbV3OutputDebug in project KeePassDX by Kunzisoft.

the class PwManagerOutputTest method testFinalKey.

public void testFinalKey() throws PwDbOutputException {
    ByteArrayOutputStream bActual = new ByteArrayOutputStream();
    PwDbV3Output pActual = new PwDbV3OutputDebug(mPM, bActual, true);
    PwDbHeader hActual = pActual.outputHeader(bActual);
    byte[] finalKey = pActual.getFinalKey(hActual);
    assertArrayEquals("Keys mismatched", mPM.finalKey, finalKey);
}
Also used : PwDbV3Output(com.keepassdroid.database.save.PwDbV3Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PwDbV3OutputDebug(com.keepassdroid.database.save.PwDbV3OutputDebug) PwDbHeader(com.keepassdroid.database.PwDbHeader)

Example 3 with PwDbV3OutputDebug

use of com.keepassdroid.database.save.PwDbV3OutputDebug in project KeePassDX by Kunzisoft.

the class PwManagerOutputTest method testPlainContent.

public void testPlainContent() throws IOException, PwDbOutputException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PwDbV3Output pos = new PwDbV3OutputDebug(mPM, bos, true);
    pos.outputPlanGroupAndEntries(bos);
    assertTrue("No output", bos.toByteArray().length > 0);
    assertArrayEquals("Group and entry output doesn't match.", mPM.postHeader, bos.toByteArray());
}
Also used : PwDbV3Output(com.keepassdroid.database.save.PwDbV3Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PwDbV3OutputDebug(com.keepassdroid.database.save.PwDbV3OutputDebug)

Example 4 with PwDbV3OutputDebug

use of com.keepassdroid.database.save.PwDbV3OutputDebug in project KeePassDX by Kunzisoft.

the class PwManagerOutputTest method testFullWrite.

public void testFullWrite() throws IOException, PwDbOutputException {
    AssetManager am = getContext().getAssets();
    InputStream is = am.open("test1.kdb");
    // Pull file into byte array (for streaming fun)
    ByteArrayOutputStream bExpected = new ByteArrayOutputStream();
    while (true) {
        int data = is.read();
        if (data == -1) {
            break;
        }
        bExpected.write(data);
    }
    ByteArrayOutputStream bActual = new ByteArrayOutputStream();
    PwDbV3Output pActual = new PwDbV3OutputDebug(mPM, bActual, true);
    pActual.output();
    // pActual.close();
    FileOutputStream fos = new FileOutputStream(TestUtil.getSdPath("test1_out.kdb"));
    fos.write(bActual.toByteArray());
    fos.close();
    assertArrayEquals("Databases do not match.", bExpected.toByteArray(), bActual.toByteArray());
}
Also used : AssetManager(android.content.res.AssetManager) PwDbV3Output(com.keepassdroid.database.save.PwDbV3Output) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PwDbV3OutputDebug(com.keepassdroid.database.save.PwDbV3OutputDebug)

Example 5 with PwDbV3OutputDebug

use of com.keepassdroid.database.save.PwDbV3OutputDebug in project KeePassDX by Kunzisoft.

the class PwManagerOutputTest method testChecksum.

public void testChecksum() throws NoSuchAlgorithmException, IOException, PwDbOutputException {
    // FileOutputStream fos = new FileOutputStream("/dev/null");
    NullOutputStream nos = new NullOutputStream();
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    DigestOutputStream dos = new DigestOutputStream(nos, md);
    PwDbV3Output pos = new PwDbV3OutputDebug(mPM, dos, true);
    pos.outputPlanGroupAndEntries(dos);
    dos.close();
    byte[] digest = md.digest();
    assertTrue("No output", digest.length > 0);
    assertArrayEquals("Hash of groups and entries failed.", mPM.dbHeader.contentsHash, digest);
}
Also used : PwDbV3Output(com.keepassdroid.database.save.PwDbV3Output) DigestOutputStream(java.security.DigestOutputStream) MessageDigest(java.security.MessageDigest) PwDbV3OutputDebug(com.keepassdroid.database.save.PwDbV3OutputDebug) NullOutputStream(com.keepassdroid.stream.NullOutputStream)

Aggregations

PwDbV3Output (com.keepassdroid.database.save.PwDbV3Output)5 PwDbV3OutputDebug (com.keepassdroid.database.save.PwDbV3OutputDebug)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AssetManager (android.content.res.AssetManager)1 PwDbHeader (com.keepassdroid.database.PwDbHeader)1 PwDbHeaderV3 (com.keepassdroid.database.PwDbHeaderV3)1 PwDbHeaderOutputV3 (com.keepassdroid.database.save.PwDbHeaderOutputV3)1 NullOutputStream (com.keepassdroid.stream.NullOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 DigestOutputStream (java.security.DigestOutputStream)1 MessageDigest (java.security.MessageDigest)1