blob: f2018a07b9b612f7a09ef9ddcf02f57ad240a29a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
package org.spongycastle.openpgp;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.spongycastle.bcpg.BCPGInputStream;
import org.spongycastle.bcpg.Packet;
import org.spongycastle.bcpg.PacketTags;
import org.spongycastle.bcpg.SignaturePacket;
import org.spongycastle.bcpg.TrustPacket;
import org.spongycastle.bcpg.UserAttributePacket;
import org.spongycastle.bcpg.UserIDPacket;
public abstract class PGPKeyRing
{
PGPKeyRing()
{
}
static BCPGInputStream wrap(InputStream in)
{
if (in instanceof BCPGInputStream)
{
return (BCPGInputStream)in;
}
return new BCPGInputStream(in);
}
static TrustPacket readOptionalTrustPacket(
BCPGInputStream pIn)
throws IOException
{
return (pIn.nextPacketTag() == PacketTags.TRUST)
? (TrustPacket) pIn.readPacket()
: null;
}
static List readSignaturesAndTrust(
BCPGInputStream pIn)
throws IOException
{
try
{
List sigList = new ArrayList();
while (pIn.nextPacketTag() == PacketTags.SIGNATURE)
{
SignaturePacket signaturePacket = (SignaturePacket)pIn.readPacket();
TrustPacket trustPacket = readOptionalTrustPacket(pIn);
sigList.add(new PGPSignature(signaturePacket, trustPacket));
}
return sigList;
}
catch (PGPException e)
{
throw new IOException("can't create signature object: " + e.getMessage()
+ ", cause: " + e.getUnderlyingException().toString());
}
}
static void readUserIDs(
BCPGInputStream pIn,
List ids,
List idTrusts,
List idSigs)
throws IOException
{
while (pIn.nextPacketTag() == PacketTags.USER_ID
|| pIn.nextPacketTag() == PacketTags.USER_ATTRIBUTE)
{
Packet obj = pIn.readPacket();
if (obj instanceof UserIDPacket)
{
UserIDPacket id = (UserIDPacket)obj;
ids.add(id);
}
else
{
UserAttributePacket user = (UserAttributePacket)obj;
ids.add(new PGPUserAttributeSubpacketVector(user.getSubpackets()));
}
idTrusts.add(readOptionalTrustPacket(pIn));
idSigs.add(readSignaturesAndTrust(pIn));
}
}
/**
* Return the first public key in the ring. In the case of a {@link PGPSecretKeyRing}
* this is also the public key of the master key pair.
*
* @return PGPPublicKey
*/
public abstract PGPPublicKey getPublicKey();
/**
* Return an iterator containing all the public keys.
*
* @return Iterator
*/
public abstract Iterator getPublicKeys();
/**
* Return the public key referred to by the passed in keyID if it
* is present.
*
* @param keyID
* @return PGPPublicKey
*/
public abstract PGPPublicKey getPublicKey(long keyID);
public abstract void encode(OutputStream outStream)
throws IOException;
public abstract byte[] getEncoded()
throws IOException;
}
|