forked from bcgit/bc-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cacd2d1
commit c905198
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
pg/src/test/java/org/bouncycastle/bcpg/test/SignatureSubpacketsTest.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,54 @@ | ||
package org.bouncycastle.bcpg.test; | ||
|
||
import org.bouncycastle.bcpg.AEADAlgorithmTags; | ||
import org.bouncycastle.bcpg.SignatureSubpacketTags; | ||
import org.bouncycastle.bcpg.sig.LibrePGPPreferredEncryptionModes; | ||
import org.bouncycastle.util.Arrays; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
public class SignatureSubpacketsTest | ||
extends AbstractPacketTest | ||
{ | ||
@Override | ||
public String getName() | ||
{ | ||
return "SignatureSubpacketsTest"; | ||
} | ||
|
||
@Override | ||
public void performTest() | ||
throws Exception | ||
{ | ||
testLibrePGPPreferredEncryptionModesSubpacket(); | ||
} | ||
|
||
private void testLibrePGPPreferredEncryptionModesSubpacket() | ||
throws IOException | ||
{ | ||
int[] algorithms = new int[] {AEADAlgorithmTags.EAX, AEADAlgorithmTags.OCB}; | ||
LibrePGPPreferredEncryptionModes encModes = new LibrePGPPreferredEncryptionModes( | ||
false, algorithms); | ||
|
||
isTrue("Encryption Modes encoding mismatch", | ||
Arrays.areEqual(algorithms, encModes.getPreferences())); | ||
isFalse("Mismatch in critical flag", encModes.isCritical()); | ||
|
||
// encode to byte array and check correctness | ||
ByteArrayOutputStream bOut = new ByteArrayOutputStream(); | ||
encModes.encode(bOut); | ||
|
||
isEncodingEqual("Packet encoding mismatch", new byte[]{ | ||
3, // length | ||
SignatureSubpacketTags.LIBREPGP_PREFERRED_ENCRYPTION_MODES, | ||
AEADAlgorithmTags.EAX, | ||
AEADAlgorithmTags.OCB | ||
}, bOut.toByteArray()); | ||
} | ||
|
||
public static void main(String[] args) | ||
{ | ||
runTest(new SignatureSubpacketsTest()); | ||
} | ||
} |
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