aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-01-14 13:05:13 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2015-01-14 13:25:38 +0100
commit73feaa974cc90c86ca63ba09b86b8a10eb1a7e18 (patch)
treeb975e15bbe18d37305668716e49fdb64854e0568 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java
parentbbc9d90c3efc2665a58f3ec69c44981b63c984b5 (diff)
downloadopen-keychain-73feaa974cc90c86ca63ba09b86b8a10eb1a7e18.tar.gz
open-keychain-73feaa974cc90c86ca63ba09b86b8a10eb1a7e18.tar.bz2
open-keychain-73feaa974cc90c86ca63ba09b86b8a10eb1a7e18.zip
small fixes to user attribute handling
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java25
1 files changed, 22 insertions, 3 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java
index 248ef11aa..da6d8b287 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java
@@ -22,6 +22,7 @@ import org.spongycastle.bcpg.BCPGOutputStream;
import org.spongycastle.bcpg.Packet;
import org.spongycastle.bcpg.UserAttributePacket;
import org.spongycastle.bcpg.UserAttributeSubpacket;
+import org.spongycastle.bcpg.UserAttributeSubpacketInputStream;
import org.spongycastle.bcpg.UserAttributeSubpacketTags;
import org.spongycastle.openpgp.PGPUserAttributeSubpacketVector;
@@ -30,6 +31,8 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectStreamException;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
public class WrappedUserAttribute implements Serializable {
@@ -72,9 +75,17 @@ public class WrappedUserAttribute implements Serializable {
return out.toByteArray();
}
- public static WrappedUserAttribute fromData (byte[] data) {
- // TODO
- return null;
+ public static WrappedUserAttribute fromData (byte[] data) throws IOException {
+ UserAttributeSubpacketInputStream in =
+ new UserAttributeSubpacketInputStream(new ByteArrayInputStream(data));
+ ArrayList<UserAttributeSubpacket> list = new ArrayList<UserAttributeSubpacket>();
+ while (in.available() > 0) {
+ list.add(in.readPacket());
+ }
+ UserAttributeSubpacket[] result = new UserAttributeSubpacket[list.size()];
+ list.toArray(result);
+ return new WrappedUserAttribute(
+ new PGPUserAttributeSubpacketVector(result));
}
/** Writes this object to an ObjectOutputStream. */
@@ -102,4 +113,12 @@ public class WrappedUserAttribute implements Serializable {
private void readObjectNoData() throws ObjectStreamException {
}
+ @Override
+ public boolean equals(Object o) {
+ if (!WrappedUserAttribute.class.isInstance(o)) {
+ return false;
+ }
+ return mVector.equals(((WrappedUserAttribute) o).mVector);
+ }
+
}