1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-17 18:02:05 +01:00

Add more direct PDA tests

This commit is contained in:
Paul Schaub 2022-10-21 00:40:40 +02:00
parent 977f8c4101
commit 3977d1f407

View file

@ -1,10 +1,11 @@
package org.pgpainless.decryption_verification.syntax_check;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.pgpainless.exception.MalformedOpenPgpMessageException;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class PDATest {
@ -15,11 +16,11 @@ public class PDATest {
*/
@Test
public void testSimpleLiteralMessageIsValid() throws MalformedOpenPgpMessageException {
PDA automaton = new PDA();
automaton.next(InputAlphabet.LiteralData);
automaton.next(InputAlphabet.EndOfSequence);
PDA check = new PDA();
check.next(InputAlphabet.LiteralData);
check.next(InputAlphabet.EndOfSequence);
assertTrue(automaton.isValid());
assertTrue(check.isValid());
}
/**
@ -29,13 +30,13 @@ public class PDATest {
*/
@Test
public void testSimpleOpsSignedMesssageIsValid() throws MalformedOpenPgpMessageException {
PDA automaton = new PDA();
automaton.next(InputAlphabet.OnePassSignature);
automaton.next(InputAlphabet.LiteralData);
automaton.next(InputAlphabet.Signature);
automaton.next(InputAlphabet.EndOfSequence);
PDA check = new PDA();
check.next(InputAlphabet.OnePassSignature);
check.next(InputAlphabet.LiteralData);
check.next(InputAlphabet.Signature);
check.next(InputAlphabet.EndOfSequence);
assertTrue(automaton.isValid());
assertTrue(check.isValid());
}
@ -46,12 +47,12 @@ public class PDATest {
*/
@Test
public void testSimplePrependSignedMessageIsValid() throws MalformedOpenPgpMessageException {
PDA automaton = new PDA();
automaton.next(InputAlphabet.Signature);
automaton.next(InputAlphabet.LiteralData);
automaton.next(InputAlphabet.EndOfSequence);
PDA check = new PDA();
check.next(InputAlphabet.Signature);
check.next(InputAlphabet.LiteralData);
check.next(InputAlphabet.EndOfSequence);
assertTrue(automaton.isValid());
assertTrue(check.isValid());
}
@ -62,14 +63,53 @@ public class PDATest {
*/
@Test
public void testOPSSignedCompressedMessageIsValid() throws MalformedOpenPgpMessageException {
PDA automaton = new PDA();
automaton.next(InputAlphabet.OnePassSignature);
automaton.next(InputAlphabet.CompressedData);
PDA check = new PDA();
check.next(InputAlphabet.OnePassSignature);
check.next(InputAlphabet.CompressedData);
// Here would be a nested PDA for the LiteralData packet
automaton.next(InputAlphabet.Signature);
automaton.next(InputAlphabet.EndOfSequence);
check.next(InputAlphabet.Signature);
check.next(InputAlphabet.EndOfSequence);
assertTrue(automaton.isValid());
assertTrue(check.isValid());
}
@Test
public void testTwoLiteralDataIsNotValid() {
PDA check = new PDA();
check.next(InputAlphabet.LiteralData);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputAlphabet.LiteralData));
}
@Test
public void testTrailingSigIsNotValid() {
PDA check = new PDA();
check.next(InputAlphabet.LiteralData);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputAlphabet.Signature));
}
@Test
public void testOPSWithPrependedSigIsValid() {
PDA check = new PDA();
check.next(InputAlphabet.Signature);
check.next(InputAlphabet.OnePassSignature);
check.next(InputAlphabet.LiteralData);
check.next(InputAlphabet.Signature);
check.next(InputAlphabet.EndOfSequence);
assertTrue(check.isValid());
}
@Test
public void testPrependedSigInsideOPSSignedMessageIsValid() {
PDA check = new PDA();
check.next(InputAlphabet.OnePassSignature);
check.next(InputAlphabet.Signature);
check.next(InputAlphabet.LiteralData);
check.next(InputAlphabet.Signature);
check.next(InputAlphabet.EndOfSequence);
assertTrue(check.isValid());
}
}