1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-12 23:31:08 +01:00

Rename syntax checker enums to screaming snake case

This commit is contained in:
Paul Schaub 2023-08-24 16:35:40 +02:00
parent 603f07d014
commit 1ab5377f70
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
7 changed files with 108 additions and 108 deletions

View file

@ -8,32 +8,32 @@ enum class InputSymbol {
/**
* A [PGPLiteralData] packet.
*/
LiteralData,
LITERAL_DATA,
/**
* A [PGPSignatureList] object.
*/
Signature,
SIGNATURE,
/**
* A [PGPOnePassSignatureList] object.
*/
OnePassSignature,
ONE_PASS_SIGNATURE,
/**
* A [PGPCompressedData] packet.
* The contents of this packet MUST form a valid OpenPGP message, so a nested PDA is opened to verify
* its nested packet sequence.
*/
CompressedData,
COMPRESSED_DATA,
/**
* A [PGPEncryptedDataList] object.
* This object combines multiple ESKs and the corresponding Symmetrically Encrypted
* (possibly Integrity Protected) Data packet.
*/
EncryptedData,
ENCRYPTED_DATA,
/**
* Marks the end of a (sub-) sequence.
* This input is given if the end of an OpenPGP message is reached.
* This might be the case for the end of the whole ciphertext, or the end of a packet with nested contents
* (e.g. the end of a Compressed Data packet).
*/
EndOfSequence
END_OF_SEQUENCE
}

View file

@ -17,72 +17,72 @@ class OpenPgpMessageSyntax : Syntax {
override fun transition(from: State, input: InputSymbol, stackItem: StackSymbol?): Transition {
return when (from) {
State.OpenPgpMessage -> fromOpenPgpMessage(input, stackItem)
State.LiteralMessage -> fromLiteralMessage(input, stackItem)
State.CompressedMessage -> fromCompressedMessage(input, stackItem)
State.EncryptedMessage -> fromEncryptedMessage(input, stackItem)
State.Valid -> fromValid(input, stackItem)
State.OPENPGP_MESSAGE -> fromOpenPgpMessage(input, stackItem)
State.LITERAL_MESSAGE -> fromLiteralMessage(input, stackItem)
State.COMPRESSED_MESSAGE -> fromCompressedMessage(input, stackItem)
State.ENCRYPTED_MESSAGE -> fromEncryptedMessage(input, stackItem)
State.VALID -> fromValid(input, stackItem)
else -> throw MalformedOpenPgpMessageException(from, input, stackItem)
}
}
fun fromOpenPgpMessage(input: InputSymbol, stackItem: StackSymbol?): Transition {
if (stackItem !== StackSymbol.msg) {
throw MalformedOpenPgpMessageException(State.OpenPgpMessage, input, stackItem)
if (stackItem !== StackSymbol.MSG) {
throw MalformedOpenPgpMessageException(State.OPENPGP_MESSAGE, input, stackItem)
}
return when (input) {
InputSymbol.LiteralData -> Transition(State.LiteralMessage)
InputSymbol.Signature -> Transition(State.OpenPgpMessage, StackSymbol.msg)
InputSymbol.OnePassSignature -> Transition(State.OpenPgpMessage, StackSymbol.ops, StackSymbol.msg)
InputSymbol.CompressedData -> Transition(State.CompressedMessage)
InputSymbol.EncryptedData -> Transition(State.EncryptedMessage)
InputSymbol.EndOfSequence -> throw MalformedOpenPgpMessageException(State.OpenPgpMessage, input, stackItem)
else -> throw MalformedOpenPgpMessageException(State.OpenPgpMessage, input, stackItem)
InputSymbol.LITERAL_DATA -> Transition(State.LITERAL_MESSAGE)
InputSymbol.SIGNATURE -> Transition(State.OPENPGP_MESSAGE, StackSymbol.MSG)
InputSymbol.ONE_PASS_SIGNATURE -> Transition(State.OPENPGP_MESSAGE, StackSymbol.OPS, StackSymbol.MSG)
InputSymbol.COMPRESSED_DATA -> Transition(State.COMPRESSED_MESSAGE)
InputSymbol.ENCRYPTED_DATA -> Transition(State.ENCRYPTED_MESSAGE)
InputSymbol.END_OF_SEQUENCE -> throw MalformedOpenPgpMessageException(State.OPENPGP_MESSAGE, input, stackItem)
else -> throw MalformedOpenPgpMessageException(State.OPENPGP_MESSAGE, input, stackItem)
}
}
@Throws(MalformedOpenPgpMessageException::class)
fun fromLiteralMessage(input: InputSymbol, stackItem: StackSymbol?): Transition {
if (input == InputSymbol.Signature && stackItem == StackSymbol.ops) {
return Transition(State.LiteralMessage)
if (input == InputSymbol.SIGNATURE && stackItem == StackSymbol.OPS) {
return Transition(State.LITERAL_MESSAGE)
}
if (input == InputSymbol.EndOfSequence && stackItem == StackSymbol.terminus) {
return Transition(State.Valid)
if (input == InputSymbol.END_OF_SEQUENCE && stackItem == StackSymbol.TERMINUS) {
return Transition(State.VALID)
}
throw MalformedOpenPgpMessageException(State.LiteralMessage, input, stackItem)
throw MalformedOpenPgpMessageException(State.LITERAL_MESSAGE, input, stackItem)
}
@Throws(MalformedOpenPgpMessageException::class)
fun fromCompressedMessage(input: InputSymbol, stackItem: StackSymbol?): Transition {
if (input == InputSymbol.Signature && stackItem == StackSymbol.ops) {
return Transition(State.CompressedMessage)
if (input == InputSymbol.SIGNATURE && stackItem == StackSymbol.OPS) {
return Transition(State.COMPRESSED_MESSAGE)
}
if (input == InputSymbol.EndOfSequence && stackItem == StackSymbol.terminus) {
return Transition(State.Valid)
if (input == InputSymbol.END_OF_SEQUENCE && stackItem == StackSymbol.TERMINUS) {
return Transition(State.VALID)
}
throw MalformedOpenPgpMessageException(State.CompressedMessage, input, stackItem)
throw MalformedOpenPgpMessageException(State.COMPRESSED_MESSAGE, input, stackItem)
}
@Throws(MalformedOpenPgpMessageException::class)
fun fromEncryptedMessage(input: InputSymbol, stackItem: StackSymbol?): Transition {
if (input == InputSymbol.Signature && stackItem == StackSymbol.ops) {
return Transition(State.EncryptedMessage)
if (input == InputSymbol.SIGNATURE && stackItem == StackSymbol.OPS) {
return Transition(State.ENCRYPTED_MESSAGE)
}
if (input == InputSymbol.EndOfSequence && stackItem == StackSymbol.terminus) {
return Transition(State.Valid)
if (input == InputSymbol.END_OF_SEQUENCE && stackItem == StackSymbol.TERMINUS) {
return Transition(State.VALID)
}
throw MalformedOpenPgpMessageException(State.EncryptedMessage, input, stackItem)
throw MalformedOpenPgpMessageException(State.ENCRYPTED_MESSAGE, input, stackItem)
}
@Throws(MalformedOpenPgpMessageException::class)
fun fromValid(input: InputSymbol, stackItem: StackSymbol?): Transition {
if (input == InputSymbol.EndOfSequence) {
if (input == InputSymbol.END_OF_SEQUENCE) {
// allow subsequent read() calls.
return Transition(State.Valid)
return Transition(State.VALID)
}
throw MalformedOpenPgpMessageException(State.Valid, input, stackItem)
throw MalformedOpenPgpMessageException(State.VALID, input, stackItem)
}
}

View file

@ -33,7 +33,7 @@ class PDA constructor(
/**
* Default constructor which initializes the PDA to work with the [OpenPgpMessageSyntax].
*/
constructor(): this(OpenPgpMessageSyntax(), State.OpenPgpMessage, StackSymbol.terminus, StackSymbol.msg)
constructor(): this(OpenPgpMessageSyntax(), State.OPENPGP_MESSAGE, StackSymbol.TERMINUS, StackSymbol.MSG)
/**
* Process the next [InputSymbol].
@ -78,7 +78,7 @@ class PDA constructor(
*
* @return true if valid, false otherwise
*/
fun isValid(): Boolean = state == State.Valid && stack.isEmpty()
fun isValid(): Boolean = state == State.VALID && stack.isEmpty()
/**
* Throw a [MalformedOpenPgpMessageException] if the pda is not in a valid state right now.

View file

@ -8,13 +8,13 @@ enum class StackSymbol {
/**
* OpenPGP Message.
*/
msg,
MSG,
/**
* OnePassSignature (in case of BC this represents a OnePassSignatureList).
*/
ops,
OPS,
/**
* Special symbol representing the end of the message.
*/
terminus
TERMINUS
}

View file

@ -8,9 +8,9 @@ package org.pgpainless.decryption_verification.syntax_check
* Set of states of the automaton.
*/
enum class State {
OpenPgpMessage,
LiteralMessage,
CompressedMessage,
EncryptedMessage,
Valid
OPENPGP_MESSAGE,
LITERAL_MESSAGE,
COMPRESSED_MESSAGE,
ENCRYPTED_MESSAGE,
VALID
}