Skip to content

Commit

Permalink
More detailed secret key packet testing
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Jun 12, 2024
1 parent 7467c55 commit c2e45f0
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package org.bouncycastle.bcpg.test;

import org.bouncycastle.bcpg.*;
import org.bouncycastle.bcpg.ArmoredInputStream;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.bcpg.BCPGInputStream;
import org.bouncycastle.bcpg.BCPGOutputStream;
import org.bouncycastle.bcpg.PacketFormat;
import org.bouncycastle.bcpg.PublicKeyPacket;
import org.bouncycastle.bcpg.SecretKeyPacket;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.bcpg.UnknownBCPGKey;
import org.bouncycastle.util.encoders.Hex;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -51,7 +59,11 @@ private void parseUnknownUnencryptedV6SecretKey()
BCPGInputStream pIn = new BCPGInputStream(aIn);
SecretKeyPacket p = (SecretKeyPacket) pIn.readPacket();

isEncodingEqual(sk.getEncoded(PacketFormat.CURRENT), p.getEncoded(PacketFormat.CURRENT));
isEquals("Packet version mismatch", PublicKeyPacket.VERSION_6, p.getPublicKeyPacket().getVersion());
isEquals("Algorithm mismatch", 99, p.getPublicKeyPacket().getAlgorithm());
isEncodingEqual("Public key encoding mismatch", Hex.decode("c0ffee"), p.getPublicKeyPacket().getKey().getEncoded());
isEncodingEqual("Secret key encoding mismatch", Hex.decode("0decaf"), p.getSecretKeyData());
isEncodingEqual("Packet encoding mismatch", sk.getEncoded(PacketFormat.CURRENT), p.getEncoded(PacketFormat.CURRENT));
}

public static void main(String[] args)
Expand Down

0 comments on commit c2e45f0

Please sign in to comment.