diff --git a/database/src/main/java/org/linguafranca/pwdb/Entry.java b/database/src/main/java/org/linguafranca/pwdb/Entry.java index a17cef26..fe49a2ec 100644 --- a/database/src/main/java/org/linguafranca/pwdb/Entry.java +++ b/database/src/main/java/org/linguafranca/pwdb/Entry.java @@ -297,7 +297,15 @@ interface Matcher { boolean getExpires(); + void setExpires(boolean expires); + Date getExpiryTime(); + /** + * Sets the expiration date of this element. See {@link org.linguafranca.pwdb.Entry#setExpires(boolean)} + * @throws IllegalArgumentException if expiryTime is null. + */ + void setExpiryTime(Date expiryTime) throws IllegalArgumentException; + Date getLastModificationTime(); } diff --git a/dom/src/main/java/org/linguafranca/pwdb/kdbx/dom/DomEntryWrapper.java b/dom/src/main/java/org/linguafranca/pwdb/kdbx/dom/DomEntryWrapper.java index f13555bb..8caee2c3 100644 --- a/dom/src/main/java/org/linguafranca/pwdb/kdbx/dom/DomEntryWrapper.java +++ b/dom/src/main/java/org/linguafranca/pwdb/kdbx/dom/DomEntryWrapper.java @@ -180,6 +180,11 @@ public boolean getExpires() { return content != null && content.equalsIgnoreCase("true"); } + @Override + public void setExpires(boolean expires) { + DomHelper.setElementContent(DomHelper.EXPIRES_ELEMENT_NAME, element, expires ? "True" : "False"); + } + @Override public Date getExpiryTime() { try { @@ -189,6 +194,13 @@ public Date getExpiryTime() { } } + @Override + public void setExpiryTime(Date expiryTime) throws IllegalArgumentException { + if (expiryTime == null) throw new IllegalArgumentException("expiryTime may not be null"); + String formatted = DomHelper.dateFormatter.format(expiryTime); + DomHelper.setElementContent(DomHelper.EXPIRY_TIME_ELEMENT_NAME, element, formatted); + } + @Override public Date getLastModificationTime() { try { diff --git a/jaxb/src/main/java/org/linguafranca/pwdb/kdbx/jaxb/JaxbEntry.java b/jaxb/src/main/java/org/linguafranca/pwdb/kdbx/jaxb/JaxbEntry.java index 17e61ccd..3fb7e85b 100644 --- a/jaxb/src/main/java/org/linguafranca/pwdb/kdbx/jaxb/JaxbEntry.java +++ b/jaxb/src/main/java/org/linguafranca/pwdb/kdbx/jaxb/JaxbEntry.java @@ -219,11 +219,22 @@ public boolean getExpires() { return delegate.getTimes().getExpires(); } + @Override + public void setExpires(boolean expires) { + delegate.getTimes().setExpires(true); + } + @Override public Date getExpiryTime() { return delegate.getTimes().getExpiryTime(); } + @Override + public void setExpiryTime(Date expiryTime) throws IllegalArgumentException { + if (expiryTime == null) throw new IllegalArgumentException("expiryTime may not be null"); + delegate.getTimes().setExpiryTime(expiryTime); + } + @Override public Date getLastModificationTime() { return delegate.getTimes().getLastModificationTime(); diff --git a/kdb/src/main/java/org/linguafranca/pwdb/kdb/KdbEntry.java b/kdb/src/main/java/org/linguafranca/pwdb/kdb/KdbEntry.java index cd832f83..e6b90aa9 100644 --- a/kdb/src/main/java/org/linguafranca/pwdb/kdb/KdbEntry.java +++ b/kdb/src/main/java/org/linguafranca/pwdb/kdb/KdbEntry.java @@ -43,6 +43,7 @@ public class KdbEntry extends AbstractEntry getBinaryPropertyNames() { throw new UnsupportedOperationException(); } + @Override + public void setExpires(boolean expires) { + this.expires = expires; + } + @Override public boolean getExpires() { - return false; + return expires; } @Override diff --git a/simple/src/main/java/org/linguafranca/pwdb/kdbx/simple/SimpleEntry.java b/simple/src/main/java/org/linguafranca/pwdb/kdbx/simple/SimpleEntry.java index a7157fef..6f2b16d5 100644 --- a/simple/src/main/java/org/linguafranca/pwdb/kdbx/simple/SimpleEntry.java +++ b/simple/src/main/java/org/linguafranca/pwdb/kdbx/simple/SimpleEntry.java @@ -219,11 +219,22 @@ public boolean getExpires() { return times.getExpires(); } + @Override + public void setExpires(boolean expires) { + times.setExpires(expires); + } + @Override public Date getExpiryTime() { return times.getExpiryTime(); } + @Override + public void setExpiryTime(Date expiryTime) throws IllegalArgumentException { + if (expiryTime == null) throw new IllegalArgumentException("expiryTime may not be null"); + times.setExpiryTime(expiryTime); + } + @Override public Date getLastModificationTime() { return times.getLastModificationTime();