|
| 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