Skip to content

Commit

Permalink
Add UnknownBCPGKeyPairTest to check getBitStrength()
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Sep 10, 2024
1 parent 3f618be commit 76de711
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public class RegressionTest

new Curve25519PrivateKeyEncodingTest(),
new EdDSAKeyConversionWithLeadingZeroTest(),
new ECDSAKeyPairTest()
new ECDSAKeyPairTest(),
new UnknownBCPGKeyPairTest()
};

public static void main(String[] args)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.bouncycastle.openpgp.test;

import org.bouncycastle.bcpg.PublicKeyPacket;
import org.bouncycastle.bcpg.PublicSubkeyPacket;
import org.bouncycastle.bcpg.UnknownBCPGKey;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
import org.bouncycastle.util.encoders.Hex;

public class UnknownBCPGKeyPairTest
extends AbstractPgpKeyPairTest
{
@Override
public String getName()
{
return "UnknownBCPGKeyPairTest";
}

@Override
public void performTest()
throws Exception
{
testGetBitStrength();
}

private void testGetBitStrength()
throws PGPException
{
byte[] raw = Hex.decode("decaffc0ffeebabe"); // 8 octets = 64-bit key size
UnknownBCPGKey key = new UnknownBCPGKey(raw.length, raw);
PublicKeyPacket packet = new PublicSubkeyPacket(
PublicKeyPacket.VERSION_6,
99, // unknown algorithm ID
currentTimeRounded(),
key);
PGPPublicKey pgpKey = new PGPPublicKey(packet, new BcKeyFingerprintCalculator());
isEquals("Unknown key getBitStrength() mismatch", 64, pgpKey.getBitStrength());
}

public static void main(String[] args)
{
runTest(new UnknownBCPGKeyPairTest());
}
}

0 comments on commit 76de711

Please sign in to comment.