Skip to content

Commit 475f0de

Browse files
committed
Add UnknownBCPGKeyPairTest to check getBitStrength()
1 parent 438e5b1 commit 475f0de

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

pg/src/test/java/org/bouncycastle/openpgp/test/RegressionTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public class RegressionTest
7676

7777
new Curve25519PrivateKeyEncodingTest(),
7878
new EdDSAKeyConversionWithLeadingZeroTest(),
79-
new ECDSAKeyPairTest()
79+
new ECDSAKeyPairTest(),
80+
new UnknownBCPGKeyPairTest()
8081
};
8182

8283
public static void main(String[] args)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.bouncycastle.openpgp.test;
2+
3+
import org.bouncycastle.bcpg.PublicKeyPacket;
4+
import org.bouncycastle.bcpg.PublicSubkeyPacket;
5+
import org.bouncycastle.bcpg.UnknownBCPGKey;
6+
import org.bouncycastle.openpgp.PGPException;
7+
import org.bouncycastle.openpgp.PGPPublicKey;
8+
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
9+
import org.bouncycastle.util.encoders.Hex;
10+
11+
public class UnknownBCPGKeyPairTest
12+
extends AbstractPgpKeyPairTest
13+
{
14+
@Override
15+
public String getName()
16+
{
17+
return "UnknownBCPGKeyPairTest";
18+
}
19+
20+
@Override
21+
public void performTest()
22+
throws Exception
23+
{
24+
testGetBitStrength();
25+
}
26+
27+
private void testGetBitStrength()
28+
throws PGPException
29+
{
30+
byte[] raw = Hex.decode("decaffc0ffeebabe"); // 8 octets = 64-bit key size
31+
UnknownBCPGKey key = new UnknownBCPGKey(raw.length, raw);
32+
PublicKeyPacket packet = new PublicSubkeyPacket(
33+
PublicKeyPacket.VERSION_6,
34+
99, // unknown algorithm ID
35+
currentTimeRounded(),
36+
key);
37+
PGPPublicKey pgpKey = new PGPPublicKey(packet, new BcKeyFingerprintCalculator());
38+
isEquals("Unknown key getBitStrength() mismatch", 64, pgpKey.getBitStrength());
39+
}
40+
41+
public static void main(String[] args)
42+
{
43+
runTest(new UnknownBCPGKeyPairTest());
44+
}
45+
}

0 commit comments

Comments
 (0)