|
| 1 | +package org.bouncycastle.bcpg.test; |
| 2 | + |
| 3 | +import org.bouncycastle.bcpg.*; |
| 4 | +import org.bouncycastle.util.encoders.Hex; |
| 5 | + |
| 6 | +import java.io.ByteArrayInputStream; |
| 7 | +import java.io.ByteArrayOutputStream; |
| 8 | +import java.io.IOException; |
| 9 | +import java.util.Date; |
| 10 | + |
| 11 | +public class UnknownSecretKeyPacketTest |
| 12 | + extends AbstractPacketTest |
| 13 | +{ |
| 14 | + @Override |
| 15 | + public String getName() |
| 16 | + { |
| 17 | + return "UnknownSecretKeyPacketTest"; |
| 18 | + } |
| 19 | + |
| 20 | + @Override |
| 21 | + public void performTest() |
| 22 | + throws Exception |
| 23 | + { |
| 24 | + parseUnknownUnencryptedV6SecretKey(); |
| 25 | + } |
| 26 | + |
| 27 | + private void parseUnknownUnencryptedV6SecretKey() |
| 28 | + throws IOException |
| 29 | + { |
| 30 | + Date creationTime = new Date((new Date().getTime() / 1000) * 1000); |
| 31 | + SecretKeyPacket sk = new SecretKeyPacket( |
| 32 | + new PublicKeyPacket( |
| 33 | + PublicKeyPacket.VERSION_6, |
| 34 | + 99, |
| 35 | + creationTime, |
| 36 | + new UnknownBCPGKey(3, Hex.decode("c0ffee"))), |
| 37 | + SymmetricKeyAlgorithmTags.NULL, |
| 38 | + null, |
| 39 | + null, |
| 40 | + Hex.decode("0decaf")); |
| 41 | + |
| 42 | + ByteArrayOutputStream bOut = new ByteArrayOutputStream(); |
| 43 | + ArmoredOutputStream aOut = new ArmoredOutputStream(bOut); |
| 44 | + BCPGOutputStream pOut = new BCPGOutputStream(aOut, PacketFormat.CURRENT); |
| 45 | + sk.encode(pOut); |
| 46 | + pOut.close(); |
| 47 | + aOut.close(); |
| 48 | + |
| 49 | + ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray()); |
| 50 | + ArmoredInputStream aIn = new ArmoredInputStream(bIn); |
| 51 | + BCPGInputStream pIn = new BCPGInputStream(aIn); |
| 52 | + SecretKeyPacket p = (SecretKeyPacket) pIn.readPacket(); |
| 53 | + |
| 54 | + isEncodingEqual(sk.getEncoded(PacketFormat.CURRENT), p.getEncoded(PacketFormat.CURRENT)); |
| 55 | + } |
| 56 | + |
| 57 | + public static void main(String[] args) |
| 58 | + { |
| 59 | + runTest(new UnknownSecretKeyPacketTest()); |
| 60 | + } |
| 61 | +} |
0 commit comments