01: package org.bouncycastle.openpgp;
02:
03: import org.bouncycastle.bcpg.UserAttributeSubpacket;
04: import org.bouncycastle.bcpg.UserAttributeSubpacketTags;
05: import org.bouncycastle.bcpg.attr.ImageAttribute;
06:
07: /**
08: * Container for a list of user attribute subpackets.
09: */
10: public class PGPUserAttributeSubpacketVector {
11: UserAttributeSubpacket[] packets;
12:
13: PGPUserAttributeSubpacketVector(UserAttributeSubpacket[] packets) {
14: this .packets = packets;
15: }
16:
17: public UserAttributeSubpacket getSubpacket(int type) {
18: for (int i = 0; i != packets.length; i++) {
19: if (packets[i].getType() == type) {
20: return packets[i];
21: }
22: }
23:
24: return null;
25: }
26:
27: public ImageAttribute getImageAttribute() {
28: UserAttributeSubpacket p = this
29: .getSubpacket(UserAttributeSubpacketTags.IMAGE_ATTRIBUTE);
30:
31: if (p == null) {
32: return null;
33: }
34:
35: return (ImageAttribute) p;
36: }
37:
38: UserAttributeSubpacket[] toSubpacketArray() {
39: return packets;
40: }
41:
42: public boolean equals(Object o) {
43: if (o == this ) {
44: return true;
45: }
46:
47: if (o instanceof PGPUserAttributeSubpacketVector) {
48: PGPUserAttributeSubpacketVector other = (PGPUserAttributeSubpacketVector) o;
49:
50: if (other.packets.length != packets.length) {
51: return false;
52: }
53:
54: for (int i = 0; i != packets.length; i++) {
55: if (!other.packets[i].equals(packets[i])) {
56: return false;
57: }
58: }
59:
60: return true;
61: }
62:
63: return false;
64: }
65:
66: public int hashCode() {
67: int code = 0;
68:
69: for (int i = 0; i != packets.length; i++) {
70: code ^= packets[i].hashCode();
71: }
72:
73: return code;
74: }
75: }
|