mirrored from https://www.bouncycastle.org/repositories/bc-java
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UnknownBCPGKeyPairTest to check getBitStrength()
- Loading branch information
1 parent
3f618be
commit 76de711
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
pg/src/test/java/org/bouncycastle/openpgp/test/UnknownBCPGKeyPairTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |