01: package org.bouncycastle.bcpg;
02:
03: import org.bouncycastle.util.Arrays;
04:
05: import java.io.IOException;
06: import java.io.OutputStream;
07:
08: /**
09: * Basic type for a PGP Signature sub-packet.
10: */
11: public class UserAttributeSubpacket {
12: int type;
13:
14: protected byte[] data;
15:
16: protected UserAttributeSubpacket(int type, byte[] data) {
17: this .type = type;
18: this .data = data;
19: }
20:
21: public int getType() {
22: return type;
23: }
24:
25: /**
26: * return the generic data making up the packet.
27: */
28: public byte[] getData() {
29: return data;
30: }
31:
32: public void encode(OutputStream out) throws IOException {
33: int bodyLen = data.length + 1;
34:
35: if (bodyLen < 192) {
36: out.write((byte) bodyLen);
37: } else if (bodyLen <= 8383) {
38: bodyLen -= 192;
39:
40: out.write((byte) (((bodyLen >> 8) & 0xff) + 192));
41: out.write((byte) bodyLen);
42: } else {
43: out.write(0xff);
44: out.write((byte) (bodyLen >> 24));
45: out.write((byte) (bodyLen >> 16));
46: out.write((byte) (bodyLen >> 8));
47: out.write((byte) bodyLen);
48: }
49:
50: out.write(type);
51: out.write(data);
52: }
53:
54: public boolean equals(Object o) {
55: if (o == this ) {
56: return true;
57: }
58:
59: if (!(o instanceof UserAttributeSubpacket)) {
60: return false;
61: }
62:
63: UserAttributeSubpacket other = (UserAttributeSubpacket) o;
64:
65: return this .type == other.type
66: && Arrays.areEqual(this .data, other.data);
67: }
68:
69: public int hashCode() {
70: return type ^ Arrays.hashCode(data);
71: }
72: }
|