From 8081d88656ab9e94969da9edde95725d77df2a3d Mon Sep 17 00:00:00 2001 From: Brian Pellin Date: Thu, 1 Jul 2010 22:24:12 -0500 Subject: [PATCH] Keyfile fix. --- AndroidManifest.xml | 2 +- CHANGELOG | 3 + assets/kdb_with_xml_keyfile.kdb | Bin 0 -> 732 bytes src/com/keepassdroid/database/PwDatabase.java | 61 +--------------- .../keepassdroid/database/PwDatabaseV3.java | 7 ++ .../keepassdroid/database/PwDatabaseV4.java | 63 +++++++++++++++- .../com/keepassdroid/tests/database/Kdb3.java | 69 ++++++++++++++++++ .../com/keepassdroid/tests/database/Kdb4.java | 2 +- 8 files changed, 145 insertions(+), 62 deletions(-) create mode 100644 assets/kdb_with_xml_keyfile.kdb create mode 100644 tests/src/com/keepassdroid/tests/database/Kdb3.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index e62e958d6..a2a7a44cf 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,7 +1,7 @@ + android:versionName="1.5.6" android:versionCode="47"> !vFvrHgyfWGQOn|sO%%en$Eq-&DLOjTX(ltGvII7!XJDEwVWDQTN!bs$|6gnw>#Z~jYe`^Wn50W^$U*DrUb?2) z38fT8n~4+q8SnW?*(GerM(s!SE~jxlEhEyU9%qVST**j_ISqret5W*3<7Q74z53}2 zRF|7~A%!~7IiBQ*Mfpp`iv#e3qUTIK#O?jzXENMq8=DQRshR=Eyc*Ia_?>WYoSKJ%N z!ikSXr0O__!FfM%2zl$7d-62*2ZRa=^n%CwOPpIGoJAe{{!J-x(22;eZr4Bcg5Kq4 zq6ud-Q(j^vhQ9?R)%oTpT8=T1=8EzB!JPr$jdI~}|JKlLQ^SnbTK)e=avxSMiOKZN zM~27+m~U{IyG86@=G}hK9DBL@ZmJ#6@BZ8kyn=JN_p??K&bJ~C0RD~2j*hg>C5U~3)5;D zGjW6*& getGroups() { @@ -172,5 +234,4 @@ public class PwDatabaseV4 extends PwDatabase { public PwGroup createGroup() { return new PwGroupV4(); } - } diff --git a/tests/src/com/keepassdroid/tests/database/Kdb3.java b/tests/src/com/keepassdroid/tests/database/Kdb3.java new file mode 100644 index 000000000..ab838aebc --- /dev/null +++ b/tests/src/com/keepassdroid/tests/database/Kdb3.java @@ -0,0 +1,69 @@ +/* + * Copyright 2010 Brian Pellin. + * + * This file is part of KeePassDroid. + * + * KeePassDroid is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePassDroid is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePassDroid. If not, see . + * + */ +package com.keepassdroid.tests.database; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.content.Context; +import android.content.res.AssetManager; +import android.test.AndroidTestCase; + +import com.keepassdroid.database.exception.InvalidDBException; +import com.keepassdroid.database.load.ImporterV3; + +public class Kdb3 extends AndroidTestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + + InputStream key = getContext().getAssets().open("keyfile.key", AssetManager.ACCESS_STREAMING); + + FileOutputStream keyFile = new FileOutputStream("/sdcard/key"); + while (true) { + byte[] buf = new byte[1024]; + int read = key.read(buf); + if ( read == -1 ) { + break; + } else { + keyFile.write(buf, 0, read); + } + } + + keyFile.close(); + + } + + public void testKeyfile() throws IOException, InvalidDBException { + Context ctx = getContext(); + + AssetManager am = ctx.getAssets(); + InputStream is = am.open("kdb_with_xml_keyfile.kdb", AssetManager.ACCESS_STREAMING); + + ImporterV3 importer = new ImporterV3(); + importer.openDatabase(is, "12345", "/sdcard/key"); + + is.close(); + + + } + +} diff --git a/tests/src/com/keepassdroid/tests/database/Kdb4.java b/tests/src/com/keepassdroid/tests/database/Kdb4.java index 62c840b94..8b8e70398 100644 --- a/tests/src/com/keepassdroid/tests/database/Kdb4.java +++ b/tests/src/com/keepassdroid/tests/database/Kdb4.java @@ -74,7 +74,7 @@ public class Kdb4 extends AndroidTestCase { if ( read == -1 ) { break; } else { - keyFile.write(buf); + keyFile.write(buf, 0, read); } }