-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,065 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/de/slackspace/openkeepass/domain/Attachment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package de.slackspace.openkeepass.domain; | ||
|
||
import org.simpleframework.xml.Element; | ||
import org.simpleframework.xml.Root; | ||
|
||
/** | ||
* Represents an attachment of an {@link Entry}. | ||
* | ||
*/ | ||
@Root(strict = false, name = "Binary") | ||
public class Attachment implements KeePassFileElement { | ||
|
||
@Element(name = "Key") | ||
private String key; | ||
|
||
@Element(name = "Value") | ||
private AttachmentValue attachmentValue; | ||
|
||
private transient byte[] data; | ||
|
||
Attachment() { | ||
} | ||
|
||
public Attachment(String key, int ref) { | ||
this.key = key; | ||
this.attachmentValue = new AttachmentValue(ref); | ||
} | ||
|
||
public Attachment(String key, int ref, byte[] data) { | ||
this.key = key; | ||
this.attachmentValue = new AttachmentValue(ref); | ||
this.data = data; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public int getRef() { | ||
return attachmentValue.getRef(); | ||
} | ||
|
||
public byte[] getData() { | ||
return data; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Property [key=" + key + ", attachmentValue=" + attachmentValue + "]"; | ||
} | ||
|
||
@Override | ||
public final int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((key == null) ? 0 : key.hashCode()); | ||
result = prime * result + ((attachmentValue == null) ? 0 : attachmentValue.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public final boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (!(obj instanceof Attachment)) | ||
return false; | ||
Attachment other = (Attachment) obj; | ||
if (key == null) { | ||
if (other.key != null) | ||
return false; | ||
} else if (!key.equals(other.key)) | ||
return false; | ||
if (attachmentValue == null) { | ||
if (other.attachmentValue != null) | ||
return false; | ||
} else if (!attachmentValue.equals(other.attachmentValue)) | ||
return false; | ||
return true; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/de/slackspace/openkeepass/domain/AttachmentValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package de.slackspace.openkeepass.domain; | ||
|
||
import org.simpleframework.xml.Attribute; | ||
import org.simpleframework.xml.Root; | ||
|
||
/** | ||
* Represents the value part of an attachment. | ||
* | ||
*/ | ||
@Root(name = "Value", strict = false) | ||
public class AttachmentValue { | ||
|
||
@Attribute(name = "Ref") | ||
private int ref; | ||
|
||
AttachmentValue() { | ||
} | ||
|
||
public AttachmentValue(int ref) { | ||
this.ref = ref; | ||
} | ||
|
||
public int getRef() { | ||
return ref; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AttachmentValue [ref=" + ref + "]"; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ref; | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
AttachmentValue other = (AttachmentValue) obj; | ||
return ref == other.ref; | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/de/slackspace/openkeepass/domain/Binaries.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package de.slackspace.openkeepass.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.simpleframework.xml.ElementList; | ||
import org.simpleframework.xml.Root; | ||
|
||
/** | ||
* Represents a list of binary items in the metadata of a KeePass file. | ||
* | ||
*/ | ||
@Root(name = "Binaries", strict = false) | ||
public class Binaries { | ||
|
||
@ElementList(name = "Binary", inline = true, required = false) | ||
private List<Binary> binaryList = new ArrayList<Binary>(); | ||
|
||
Binaries() { | ||
} | ||
|
||
public Binaries(BinariesContract binariesContract) { | ||
this.binaryList = binariesContract.getBinaries(); | ||
} | ||
|
||
/** | ||
* Returns all binary items found inside the database. | ||
* | ||
* @return a list of attachments | ||
*/ | ||
public List<Binary> getBinaries() { | ||
return binaryList; | ||
} | ||
|
||
/** | ||
* Retrieves a binary item based on its id. | ||
* | ||
* @param id the id which should be searched | ||
* @return the binary item if found, null otherwise | ||
*/ | ||
public Binary getBinaryById(int id) { | ||
for (Binary binary : binaryList) { | ||
if (binary.getId() == id) { | ||
return binary; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public final int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((binaryList == null) ? 0 : binaryList.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public final boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (!(obj instanceof Binaries)) | ||
return false; | ||
Binaries other = (Binaries) obj; | ||
if (binaryList == null) { | ||
if (other.binaryList != null) | ||
return false; | ||
} else if (!binaryList.equals(other.binaryList)) | ||
return false; | ||
return true; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/de/slackspace/openkeepass/domain/BinariesBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package de.slackspace.openkeepass.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* A builder to create {@link Binaries} objects. | ||
* | ||
*/ | ||
public class BinariesBuilder implements BinariesContract { | ||
|
||
List<Binary> binaries = new ArrayList<Binary>(); | ||
|
||
public BinariesBuilder() { | ||
// default no-args constructor | ||
} | ||
|
||
public BinariesBuilder(Binaries binaries) { | ||
this.binaries = binaries.getBinaries(); | ||
} | ||
|
||
public BinariesBuilder binaries(List<Binary> binaries) { | ||
this.binaries = binaries; | ||
return this; | ||
} | ||
|
||
public BinariesBuilder addBinary(Binary binary) { | ||
binaries.add(binary); | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds a new binary item list with the values from the builder. | ||
* | ||
* @return a new Binaries object | ||
*/ | ||
public Binaries build() { | ||
return new Binaries(this); | ||
} | ||
|
||
@Override | ||
public List<Binary> getBinaries() { | ||
return binaries; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/de/slackspace/openkeepass/domain/BinariesContract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package de.slackspace.openkeepass.domain; | ||
|
||
import java.util.List; | ||
|
||
public interface BinariesContract { | ||
|
||
List<Binary> getBinaries(); | ||
} |
Oops, something went wrong.