Package org.pgpainless.decryption_verification.syntax_check

# Class PDA

java.lang.Object
org.pgpainless.decryption_verification.syntax_check.PDA

public class PDA extends 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 the `OpenPgpMessageSyntax`.
`PDA(Syntax syntax, State initialState, StackSymbol... initialStack)`
Construct a PDA with a custom `Syntax`, initial `State` and initial `StackSymbols`.

## Method Summary

Modifier and Type
Method
Description
`void`
`assertValid()`
Throw a `MalformedOpenPgpMessageException` 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 next `InputSymbol`.
`StackSymbol`
`peekStack()`
Peek at the stack, returning the topmost stack item without changing the stack.
`String`
`toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### PDA

public PDA()
Default constructor which initializes the PDA to work with the `OpenPgpMessageSyntax`.

### PDA

public PDA(@Nonnull Syntax syntax, @Nonnull State initialState, @Nonnull StackSymbol... initialStack)
Construct a PDA with a custom `Syntax`, initial `State` and initial `StackSymbols`.

Parameters:
  `syntax` - syntax
  `initialState` - initial state
  `initialStack` - zero or more initial stack items (get pushed onto the stack in order of appearance)

## Method Details

### next

public void next(@Nonnull InputSymbol input) throws MalformedOpenPgpMessageException
Process the next `InputSymbol`. This will either leave the PDA in the next state, or throw a `MalformedOpenPgpMessageException` 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 a `MalformedOpenPgpMessageException` if the pda is not in a valid state right now.

Throws:
  `MalformedOpenPgpMessageException` - if the pda is not in an acceptable state

### toString

public String toString()

Overrides:
  `toString` in class `Object`