Skip to content

Commit 4877c9e

Browse files
vanitasvitaedghgit
authored andcommitted
Implement PGPTrust pendant to TrustPacket
Avoids ClassCastException when parsing cert with TrustPacket in PGPObjectFactory
1 parent c534075 commit 4877c9e

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

pg/src/main/java/org/bouncycastle/openpgp/PGPObjectFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
import org.bouncycastle.bcpg.BCPGInputStream;
1212
import org.bouncycastle.bcpg.PacketTags;
13+
import org.bouncycastle.bcpg.TrustPacket;
1314
import org.bouncycastle.bcpg.UnknownPacket;
1415
import org.bouncycastle.bcpg.UnsupportedPacketVersionException;
1516
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
16-
import org.bouncycastle.util.Iterable;
1717

1818
/**
1919
* General class for reading a PGP object stream.
@@ -141,6 +141,8 @@ public Object nextObject()
141141
return new PGPCompressedData(in);
142142
case PacketTags.LITERAL_DATA:
143143
return new PGPLiteralData(in);
144+
case PacketTags.TRUST:
145+
return new PGPTrust(in);
144146
case PacketTags.PUBLIC_KEY_ENC_SESSION:
145147
case PacketTags.SYMMETRIC_KEY_ENC_SESSION:
146148
case PacketTags.SYMMETRIC_KEY_ENC:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.bouncycastle.openpgp;
2+
3+
import org.bouncycastle.bcpg.BCPGInputStream;
4+
import org.bouncycastle.bcpg.TrustPacket;
5+
6+
import java.io.IOException;
7+
import java.util.Arrays;
8+
9+
public class PGPTrust
10+
{
11+
12+
private final TrustPacket packet;
13+
14+
public PGPTrust(TrustPacket packet)
15+
{
16+
this.packet = packet;
17+
}
18+
19+
public PGPTrust(BCPGInputStream inputStream)
20+
throws IOException
21+
{
22+
this((TrustPacket) inputStream.readPacket());
23+
}
24+
25+
public TrustPacket getPacket()
26+
{
27+
return packet;
28+
}
29+
30+
public byte[] getLevelAndTrust()
31+
{
32+
return Arrays.copyOf(
33+
packet.getLevelAndTrustAmount(),
34+
packet.getLevelAndTrustAmount().length);
35+
}
36+
}

0 commit comments

Comments
 (0)