diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d3f7414c6..826fe2321 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -76,7 +76,9 @@
android:theme="@style/NoTitleBar">
-
+
diff --git a/res/layout/entry_view_v4.xml b/res/layout/entry_view_v4.xml
index dfcaf3530..e3a1d610e 100644
--- a/res/layout/entry_view_v4.xml
+++ b/res/layout/entry_view_v4.xml
@@ -44,10 +44,22 @@
android:src="@drawable/ic99_blank"
style="@style/WhiteOnBlack"/>
+
+
.
+ *
+ */
+package com.keepassdroid;
+
+import android.content.Intent;
+
+import com.keepassdroid.database.PwGroupId;
+import com.keepassdroid.database.PwGroupIdV3;
+import com.keepassdroid.database.PwGroupV3;
+
+public class EntryEditActivityV3 extends EntryEditActivity {
+
+ protected static void putParentId(Intent i, String parentKey, PwGroupV3 parent) {
+ i.putExtra(parentKey, parent.groupId);
+ }
+
+ @Override
+ protected PwGroupId getParentGroupId(Intent i, String key) {
+ int groupId = i.getIntExtra(key, -1);
+
+ return new PwGroupIdV3(groupId);
+ }
+}
diff --git a/src/com/keepassdroid/EntryEditActivityV4.java b/src/com/keepassdroid/EntryEditActivityV4.java
new file mode 100644
index 000000000..135e535f1
--- /dev/null
+++ b/src/com/keepassdroid/EntryEditActivityV4.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2013 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 2 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;
+
+import java.util.UUID;
+
+import android.content.Intent;
+
+import com.keepassdroid.database.PwGroupId;
+import com.keepassdroid.database.PwGroupIdV4;
+import com.keepassdroid.database.PwGroupV4;
+import com.keepassdroid.utils.Types;
+
+public class EntryEditActivityV4 extends EntryEditActivity {
+
+ protected static void putParentId(Intent i, String parentKey, PwGroupV4 parent) {
+ PwGroupId id = parent.getId();
+ PwGroupIdV4 id4 = (PwGroupIdV4) id;
+
+ i.putExtra(parentKey, Types.UUIDtoBytes(id4.getId()));
+
+ }
+
+ @Override
+ protected PwGroupId getParentGroupId(Intent i, String key) {
+ byte[] buf = i.getByteArrayExtra(key);
+ UUID id = Types.bytestoUUID(buf);
+
+ return new PwGroupIdV4(id);
+ }
+}
diff --git a/src/com/keepassdroid/database/PwEntry.java b/src/com/keepassdroid/database/PwEntry.java
index 2e5ea44aa..808bae639 100644
--- a/src/com/keepassdroid/database/PwEntry.java
+++ b/src/com/keepassdroid/database/PwEntry.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2009-2012 Brian Pellin.
+ * Copyright 2009-2013 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -43,6 +43,22 @@ public abstract class PwEntry implements Cloneable {
}
+ public static PwEntry getInstance(PwGroup parent) {
+ return PwEntry.getInstance(parent, true, true);
+ }
+
+ public static PwEntry getInstance(PwGroup parent, boolean initId, boolean initDates) {
+ if (parent instanceof PwGroupV3) {
+ return new PwEntryV3((PwGroupV3)parent);
+ }
+ else if (parent instanceof PwGroupV4) {
+ return new PwEntryV4((PwGroupV4)parent);
+ }
+ else {
+ throw new RuntimeException("Unknow PwGroup instance.");
+ }
+ }
+
@Override
public Object clone() {
PwEntry newEntry;
@@ -56,6 +72,10 @@ public abstract class PwEntry implements Cloneable {
return newEntry;
}
+ public PwEntry clone(boolean deepStrings) {
+ return (PwEntry) clone();
+ }
+
public void assign(PwEntry source) {
icon = source.icon;
}
@@ -69,13 +89,24 @@ public abstract class PwEntry implements Cloneable {
public abstract String getPassword();
public abstract String getUrl();
public abstract String getNotes();
- public abstract Date getCreate();
- public abstract Date getMod();
- public abstract Date getAccess();
- public abstract Date getExpire();
+ public abstract Date getCreationTime();
+ public abstract Date getLastModificationTime();
+ public abstract Date getLastAccessTime();
+ public abstract Date getExpiryTime();
public abstract boolean expires();
public abstract PwGroup getParent();
+ public abstract void setTitle(String title, PwDatabase db);
+ public abstract void setUsername(String user, PwDatabase db);
+ public abstract void setPassword(String pass, PwDatabase db);
+ public abstract void setUrl(String url, PwDatabase db);
+ public abstract void setNotes(String notes, PwDatabase db);
+ public abstract void setCreationTime(Date create);
+ public abstract void setLastModificationTime(Date mod);
+ public abstract void setLastAccessTime(Date access);
+ public abstract void setExpires(boolean exp);
+ public abstract void setExpiryTime(Date expires);
+
public PwIcon getIcon() {
return icon;
diff --git a/src/com/keepassdroid/database/PwEntryV3.java b/src/com/keepassdroid/database/PwEntryV3.java
index 9a5f0fa3e..1e7667728 100644
--- a/src/com/keepassdroid/database/PwEntryV3.java
+++ b/src/com/keepassdroid/database/PwEntryV3.java
@@ -1,5 +1,23 @@
/*
-KeePass for J2ME
+ * Copyright 2010-2013 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 2 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 .
+ *
+
+This file was derived from
Copyright 2007 Naomaru Itoi
@@ -25,13 +43,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package com.keepassdroid.database;
// PhoneID
+import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.UUID;
-
-import com.keepassdroid.Database;
import com.keepassdroid.utils.Types;
@@ -150,24 +167,30 @@ public class PwEntryV3 extends PwEntry {
assign(source);
}
*/
+
+ public PwEntryV3(PwGroupV3 p) {
+ this(p, true, true);
+ }
- public PwEntryV3(Database db, int parentId) {
+ public PwEntryV3(PwGroupV3 p, boolean initId, boolean initDates) {
+ parent = p;
+ groupId = ((PwGroupIdV3)parent.getId()).getId();
+
+ if (initId) {
+ Random random = new Random();
+ uuid = new byte[16];
+ random.nextBytes(uuid);
+ }
-
- parent = (PwGroupV3) db.groups.get(new PwGroupIdV3(parentId));
- groupId = parentId;
-
- Random random = new Random();
- uuid = new byte[16];
- random.nextBytes(uuid);
-
- Calendar cal = Calendar.getInstance();
- Date now = cal.getTime();
- tCreation = new PwDate(now);
- tLastAccess = new PwDate(now);
- tLastMod = new PwDate(now);
- tExpire = new PwDate(NEVER_EXPIRE);
+ if (initDates) {
+ Calendar cal = Calendar.getInstance();
+ Date now = cal.getTime();
+ tCreation = new PwDate(now);
+ tLastAccess = new PwDate(now);
+ tLastMod = new PwDate(now);
+ tExpire = new PwDate(NEVER_EXPIRE);
+ }
}
@@ -210,6 +233,19 @@ public class PwEntryV3 extends PwEntry {
+ @Override
+ public void setPassword(String pass, PwDatabase db) {
+ byte[] password;
+ try {
+ password = pass.getBytes("UTF-8");
+ setPassword(password, 0, password.length);
+ } catch (UnsupportedEncodingException e) {
+ assert false;
+ password = pass.getBytes();
+ setPassword(password, 0, password.length);
+ }
+ }
+
/**
* @return the actual binaryData byte array.
*/
@@ -327,25 +363,55 @@ public class PwEntryV3 extends PwEntry {
}
@Override
- public Date getAccess() {
+ public Date getLastAccessTime() {
return tLastAccess.getJDate();
}
@Override
- public Date getCreate() {
+ public Date getCreationTime() {
return tCreation.getJDate();
}
@Override
- public Date getExpire() {
+ public Date getExpiryTime() {
return tExpire.getJDate();
}
@Override
- public Date getMod() {
+ public Date getLastModificationTime() {
return tLastMod.getJDate();
}
+ @Override
+ public void setCreationTime(Date create) {
+ tCreation = new PwDate(create);
+
+ }
+
+ @Override
+ public void setLastModificationTime(Date mod) {
+ tLastMod = new PwDate(mod);
+
+ }
+
+ @Override
+ public void setLastAccessTime(Date access) {
+ tLastAccess = new PwDate(access);
+
+ }
+
+ @Override
+ public void setExpires(boolean expires) {
+ if (!expires) {
+ tExpire = PW_NEVER_EXPIRE;
+ }
+ }
+
+ @Override
+ public void setExpiryTime(Date expires) {
+ tExpire = new PwDate(expires);
+ }
+
@Override
public PwGroupV3 getParent() {
return parent;
@@ -370,21 +436,41 @@ public class PwEntryV3 extends PwEntry {
return username;
}
+ @Override
+ public void setUsername(String user, PwDatabase db) {
+ username = user;
+ }
+
@Override
public String getTitle() {
return title;
}
+ @Override
+ public void setTitle(String title, PwDatabase db) {
+ this.title = title;
+ }
+
@Override
public String getNotes() {
return additional;
}
+ @Override
+ public void setNotes(String notes, PwDatabase db) {
+ additional = notes;
+ }
+
@Override
public String getUrl() {
return url;
}
+ @Override
+ public void setUrl(String url, PwDatabase db) {
+ this.url = url;
+ }
+
@Override
public boolean expires() {
return ! IsNever(tExpire.getJDate());
diff --git a/src/com/keepassdroid/database/PwEntryV4.java b/src/com/keepassdroid/database/PwEntryV4.java
index b39a60556..f39d37727 100644
--- a/src/com/keepassdroid/database/PwEntryV4.java
+++ b/src/com/keepassdroid/database/PwEntryV4.java
@@ -20,6 +20,7 @@
package com.keepassdroid.database;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -40,7 +41,7 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
public PwGroupV4 parent;
public UUID uuid = PwDatabaseV4.UUID_ZERO;
- public Map strings = new HashMap();
+ public HashMap strings = new HashMap();
public Map binaries = new HashMap();
public PwIconCustom customIcon = PwIconCustom.ZERO;
public String foregroundColor = "";
@@ -82,6 +83,39 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
public PwEntryV4() {
}
+
+ public PwEntryV4(PwGroupV4 p) {
+ this(p, true, true);
+ }
+
+ public PwEntryV4(PwGroupV4 p, boolean initId, boolean initDates) {
+ parent = p;
+
+ if (initId) {
+ uuid = UUID.randomUUID();
+ }
+
+ if (initDates) {
+ Calendar cal = Calendar.getInstance();
+ Date now = cal.getTime();
+ creation = now;
+ lastAccess = now;
+ lastMod = now;
+ expires = false;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public PwEntry clone(boolean deepStrings) {
+ PwEntryV4 entry = (PwEntryV4) super.clone(deepStrings);
+
+ if (deepStrings) {
+ entry.strings = (HashMap) strings.clone();
+ }
+
+ return entry;
+ }
@Override
public void assign(PwEntry source) {
@@ -147,25 +181,81 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
}
@Override
- public Date getAccess() {
+ public Date getLastAccessTime() {
return lastAccess;
}
@Override
- public Date getCreate() {
+ public Date getCreationTime() {
return creation;
}
@Override
- public Date getExpire() {
+ public Date getExpiryTime() {
return expireDate;
}
@Override
- public Date getMod() {
+ public Date getLastModificationTime() {
return lastMod;
}
+ @Override
+ public void setTitle(String title, PwDatabase d) {
+ PwDatabaseV4 db = (PwDatabaseV4) d;
+ boolean protect = db.memoryProtection.protectTitle;
+
+ setString(STR_TITLE, title, protect);
+ }
+
+ @Override
+ public void setUsername(String user, PwDatabase d) {
+ PwDatabaseV4 db = (PwDatabaseV4) d;
+ boolean protect = db.memoryProtection.protectUserName;
+
+ setString(STR_USERNAME, user, protect);
+ }
+
+ @Override
+ public void setPassword(String pass, PwDatabase d) {
+ PwDatabaseV4 db = (PwDatabaseV4) d;
+ boolean protect = db.memoryProtection.protectPassword;
+
+ setString(STR_PASSWORD, pass, protect);
+ }
+
+ @Override
+ public void setUrl(String url, PwDatabase d) {
+ PwDatabaseV4 db = (PwDatabaseV4) d;
+ boolean protect = db.memoryProtection.protectUrl;
+
+ setString(STR_URL, url, protect);
+ }
+
+ @Override
+ public void setNotes(String notes, PwDatabase d) {
+ PwDatabaseV4 db = (PwDatabaseV4) d;
+ boolean protect = db.memoryProtection.protectNotes;
+
+ setString(STR_NOTES, notes, protect);
+ }
+
+ public void setCreationTime(Date date) {
+ creation = date;
+ }
+
+ public void setExpiryTime(Date date) {
+ expireDate = date;
+ }
+
+ public void setLastAccessTime(Date date) {
+ lastAccess = date;
+ }
+
+ public void setLastModificationTime(Date date) {
+ lastMod = date;
+ }
+
@Override
public PwGroupV4 getParent() {
return parent;
@@ -190,20 +280,9 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
return value.toString();
}
- public Date getCreationTime() {
- return creation;
- }
-
- public Date getExpiryTime() {
- return expireDate;
- }
-
- public Date getLastAccessTime() {
- return lastAccess;
- }
-
- public Date getLastModificationTime() {
- return lastMod;
+ public void setString(String key, String value, boolean protect) {
+ ProtectedString ps = new ProtectedString(protect, value);
+ strings.put(key, ps);
}
public Date getLocationChanged() {
@@ -214,23 +293,6 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
return usageCount;
}
- public void setCreationTime(Date date) {
- creation = date;
-
- }
-
- public void setExpiryTime(Date date) {
- expireDate = date;
- }
-
- public void setLastAccessTime(Date date) {
- lastAccess = date;
- }
-
- public void setLastModificationTime(Date date) {
- lastMod = date;
- }
-
public void setLocationChanged(Date date) {
parentGroupLastMod = date;
}
diff --git a/tests/src/com/keepassdroid/tests/database/Kdb4.java b/tests/src/com/keepassdroid/tests/database/Kdb4.java
index c838ee573..2f12295d2 100644
--- a/tests/src/com/keepassdroid/tests/database/Kdb4.java
+++ b/tests/src/com/keepassdroid/tests/database/Kdb4.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010 Brian Pellin.
+ * Copyright 2010-2013 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -21,6 +21,7 @@ package com.keepassdroid.tests.database;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -36,6 +37,7 @@ import com.keepassdroid.database.load.ImporterFactory;
import com.keepassdroid.database.load.ImporterV4;
import com.keepassdroid.database.save.PwDbOutput;
import com.keepassdroid.database.save.PwDbV4Output;
+import com.keepassdroid.stream.CopyInputStream;
import com.keepassdroid.tests.TestUtil;
public class Kdb4 extends AndroidTestCase {
@@ -84,11 +86,15 @@ public class Kdb4 extends AndroidTestCase {
byte[] data = bos.toByteArray();
- ByteArrayInputStream bis = new ByteArrayInputStream(data);
+ FileOutputStream fos = new FileOutputStream("/sdcard/test-out.kdbx", false);
+
+ InputStream bis = new ByteArrayInputStream(data);
+ bis = new CopyInputStream(bis, fos);
importer = new ImporterV4();
db = importer.openDatabase(bis, "12345", "");
bis.close();
+ fos.close();
}