Class PDA
- java.lang.Object
-
- org.pgpainless.decryption_verification.syntax_check.PDA
-
public class PDA extends java.lang.Object
Pushdown Automaton for validating context-free languages. In PGPainless, this class is used to validate OpenPGP message packet sequences against the allowed syntax.- See Also:
- OpenPGP Message Syntax
-
-
Constructor Summary
Constructors Constructor Description PDA()
Default constructor which initializes the PDA to work with theOpenPgpMessageSyntax
.PDA(Syntax syntax, State initialState, StackSymbol... initialStack)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assertValid()
Throw aMalformedOpenPgpMessageException
if the pda is not in a valid state right now.State
getState()
Return the current state of the PDA.boolean
isValid()
Return true, if the PDA is in a valid state (the OpenPGP message is valid).void
next(InputSymbol input)
Process the nextInputSymbol
.StackSymbol
peekStack()
Peek at the stack, returning the topmost stack item without changing the stack.java.lang.String
toString()
-
-
-
Constructor Detail
-
PDA
public PDA()
Default constructor which initializes the PDA to work with theOpenPgpMessageSyntax
.
-
PDA
public PDA(@Nonnull Syntax syntax, @Nonnull State initialState, @Nonnull StackSymbol... initialStack)
- Parameters:
syntax
- syntaxinitialState
- initial stateinitialStack
- zero or more initial stack items (get pushed onto the stack in order of appearance)
-
-
Method Detail
-
next
public void next(@Nonnull InputSymbol input) throws MalformedOpenPgpMessageException
Process the nextInputSymbol
. This will either leave the PDA in the next state, or throw aMalformedOpenPgpMessageException
if the input symbol is rejected.- Parameters:
input
- input symbol- Throws:
MalformedOpenPgpMessageException
- if the input symbol is rejected
-
getState
@Nonnull public State getState()
Return the current state of the PDA.- Returns:
- state
-
peekStack
@Nullable public StackSymbol peekStack()
Peek at the stack, returning the topmost stack item without changing the stack.- Returns:
- topmost stack item, or null if stack is empty
-
isValid
public boolean isValid()
Return true, if the PDA is in a valid state (the OpenPGP message is valid).- Returns:
- true if valid, false otherwise
-
assertValid
public void assertValid() throws MalformedOpenPgpMessageException
Throw aMalformedOpenPgpMessageException
if the pda is not in a valid state right now.- Throws:
MalformedOpenPgpMessageException
- if the pda is not in an acceptable state
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-