|
| 1 | +package org.bouncycastle.bcpg.test; |
| 2 | + |
| 3 | +import org.bouncycastle.bcpg.AEADAlgorithmTags; |
| 4 | +import org.bouncycastle.bcpg.SignatureSubpacketTags; |
| 5 | +import org.bouncycastle.bcpg.sig.LibrePGPPreferredEncryptionModes; |
| 6 | +import org.bouncycastle.util.Arrays; |
| 7 | + |
| 8 | +import java.io.ByteArrayOutputStream; |
| 9 | +import java.io.IOException; |
| 10 | + |
| 11 | +public class SignatureSubpacketsTest |
| 12 | + extends AbstractPacketTest |
| 13 | +{ |
| 14 | + @Override |
| 15 | + public String getName() |
| 16 | + { |
| 17 | + return "SignatureSubpacketsTest"; |
| 18 | + } |
| 19 | + |
| 20 | + @Override |
| 21 | + public void performTest() |
| 22 | + throws Exception |
| 23 | + { |
| 24 | + testLibrePGPPreferredEncryptionModesSubpacket(); |
| 25 | + } |
| 26 | + |
| 27 | + private void testLibrePGPPreferredEncryptionModesSubpacket() |
| 28 | + throws IOException |
| 29 | + { |
| 30 | + int[] algorithms = new int[] {AEADAlgorithmTags.EAX, AEADAlgorithmTags.OCB}; |
| 31 | + LibrePGPPreferredEncryptionModes encModes = new LibrePGPPreferredEncryptionModes( |
| 32 | + false, algorithms); |
| 33 | + |
| 34 | + isTrue("Encryption Modes encoding mismatch", |
| 35 | + Arrays.areEqual(algorithms, encModes.getPreferences())); |
| 36 | + isFalse("Mismatch in critical flag", encModes.isCritical()); |
| 37 | + |
| 38 | + // encode to byte array and check correctness |
| 39 | + ByteArrayOutputStream bOut = new ByteArrayOutputStream(); |
| 40 | + encModes.encode(bOut); |
| 41 | + |
| 42 | + isEncodingEqual("Packet encoding mismatch", new byte[]{ |
| 43 | + 3, // length |
| 44 | + SignatureSubpacketTags.LIBREPGP_PREFERRED_ENCRYPTION_MODES, |
| 45 | + AEADAlgorithmTags.EAX, |
| 46 | + AEADAlgorithmTags.OCB |
| 47 | + }, bOut.toByteArray()); |
| 48 | + } |
| 49 | + |
| 50 | + public static void main(String[] args) |
| 51 | + { |
| 52 | + runTest(new SignatureSubpacketsTest()); |
| 53 | + } |
| 54 | +} |
0 commit comments