01: package org.bouncycastle.bcpg;
02:
03: import java.io.ByteArrayOutputStream;
04: import java.io.IOException;
05: import java.util.Vector;
06:
07: /**
08: * Basic type for a user attribute packet.
09: */
10: public class UserAttributePacket extends ContainedPacket {
11: private UserAttributeSubpacket[] subpackets;
12:
13: public UserAttributePacket(BCPGInputStream in) throws IOException {
14: UserAttributeSubpacketInputStream sIn = new UserAttributeSubpacketInputStream(
15: in);
16: UserAttributeSubpacket sub;
17:
18: Vector v = new Vector();
19: while ((sub = sIn.readPacket()) != null) {
20: v.addElement(sub);
21: }
22:
23: subpackets = new UserAttributeSubpacket[v.size()];
24:
25: for (int i = 0; i != subpackets.length; i++) {
26: subpackets[i] = (UserAttributeSubpacket) v.elementAt(i);
27: }
28: }
29:
30: public UserAttributePacket(UserAttributeSubpacket[] subpackets) {
31: this .subpackets = subpackets;
32: }
33:
34: public UserAttributeSubpacket[] getSubpackets() {
35: return subpackets;
36: }
37:
38: public void encode(BCPGOutputStream out) throws IOException {
39: ByteArrayOutputStream bOut = new ByteArrayOutputStream();
40:
41: for (int i = 0; i != subpackets.length; i++) {
42: subpackets[i].encode(bOut);
43: }
44:
45: out.writePacket(USER_ATTRIBUTE, bOut.toByteArray(), false);
46: }
47: }
|