01: package org.bouncycastle.openpgp;
02:
03: import java.io.IOException;
04: import java.util.ArrayList;
05: import java.util.Iterator;
06: import java.util.List;
07:
08: import org.bouncycastle.bcpg.BCPGInputStream;
09: import org.bouncycastle.bcpg.InputStreamPacket;
10: import org.bouncycastle.bcpg.PacketTags;
11: import org.bouncycastle.bcpg.PublicKeyEncSessionPacket;
12: import org.bouncycastle.bcpg.SymmetricKeyEncSessionPacket;
13:
14: /**
15: * A holder for a list of PGP encryption method packets.
16: */
17: public class PGPEncryptedDataList {
18: List list = new ArrayList();
19: InputStreamPacket data;
20:
21: public PGPEncryptedDataList(BCPGInputStream pIn) throws IOException {
22: while (pIn.nextPacketTag() == PacketTags.PUBLIC_KEY_ENC_SESSION
23: || pIn.nextPacketTag() == PacketTags.SYMMETRIC_KEY_ENC_SESSION) {
24: list.add(pIn.readPacket());
25: }
26:
27: data = (InputStreamPacket) pIn.readPacket();
28:
29: for (int i = 0; i != list.size(); i++) {
30: if (list.get(i) instanceof SymmetricKeyEncSessionPacket) {
31: list.set(i, new PGPPBEEncryptedData(
32: (SymmetricKeyEncSessionPacket) list.get(i),
33: data));
34: } else {
35: list.set(i, new PGPPublicKeyEncryptedData(
36: (PublicKeyEncSessionPacket) list.get(i), data));
37: }
38: }
39: }
40:
41: public Object get(int index) {
42: return list.get(index);
43: }
44:
45: public int size() {
46: return list.size();
47: }
48:
49: public boolean isEmpty() {
50: return list.isEmpty();
51: }
52:
53: /**
54: * @deprecated misspelt - use getEncryptedDataObjects()
55: */
56: public Iterator getEncyptedDataObjects() {
57: return list.iterator();
58: }
59:
60: public Iterator getEncryptedDataObjects() {
61: return list.iterator();
62: }
63: }
|