1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-23 11:27:57 +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; 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.junit.jupiter.api.Test;
import org.pgpainless.exception.MalformedOpenPgpMessageException; import org.pgpainless.exception.MalformedOpenPgpMessageException;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class PDATest { public class PDATest {
@ -15,11 +16,11 @@ public class PDATest {
*/ */
@Test @Test
public void testSimpleLiteralMessageIsValid() throws MalformedOpenPgpMessageException { public void testSimpleLiteralMessageIsValid() throws MalformedOpenPgpMessageException {
PDA automaton = new PDA(); PDA check = new PDA();
automaton.next(InputAlphabet.LiteralData); check.next(InputAlphabet.LiteralData);
automaton.next(InputAlphabet.EndOfSequence); check.next(InputAlphabet.EndOfSequence);
assertTrue(automaton.isValid()); assertTrue(check.isValid());
} }
/** /**
@ -29,13 +30,13 @@ public class PDATest {
*/ */
@Test @Test
public void testSimpleOpsSignedMesssageIsValid() throws MalformedOpenPgpMessageException { public void testSimpleOpsSignedMesssageIsValid() throws MalformedOpenPgpMessageException {
PDA automaton = new PDA(); PDA check = new PDA();
automaton.next(InputAlphabet.OnePassSignature); check.next(InputAlphabet.OnePassSignature);
automaton.next(InputAlphabet.LiteralData); check.next(InputAlphabet.LiteralData);
automaton.next(InputAlphabet.Signature); check.next(InputAlphabet.Signature);
automaton.next(InputAlphabet.EndOfSequence); check.next(InputAlphabet.EndOfSequence);
assertTrue(automaton.isValid()); assertTrue(check.isValid());
} }
@ -46,12 +47,12 @@ public class PDATest {
*/ */
@Test @Test
public void testSimplePrependSignedMessageIsValid() throws MalformedOpenPgpMessageException { public void testSimplePrependSignedMessageIsValid() throws MalformedOpenPgpMessageException {
PDA automaton = new PDA(); PDA check = new PDA();
automaton.next(InputAlphabet.Signature); check.next(InputAlphabet.Signature);
automaton.next(InputAlphabet.LiteralData); check.next(InputAlphabet.LiteralData);
automaton.next(InputAlphabet.EndOfSequence); check.next(InputAlphabet.EndOfSequence);
assertTrue(automaton.isValid()); assertTrue(check.isValid());
} }
@ -62,14 +63,53 @@ public class PDATest {
*/ */
@Test @Test
public void testOPSSignedCompressedMessageIsValid() throws MalformedOpenPgpMessageException { public void testOPSSignedCompressedMessageIsValid() throws MalformedOpenPgpMessageException {
PDA automaton = new PDA(); PDA check = new PDA();
automaton.next(InputAlphabet.OnePassSignature); check.next(InputAlphabet.OnePassSignature);
automaton.next(InputAlphabet.CompressedData); check.next(InputAlphabet.CompressedData);
// Here would be a nested PDA for the LiteralData packet // Here would be a nested PDA for the LiteralData packet
automaton.next(InputAlphabet.Signature); check.next(InputAlphabet.Signature);
automaton.next(InputAlphabet.EndOfSequence); 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());
}
} }