1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-23 03:17:58 +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

@ -342,7 +342,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
private void processLiteralData() throws IOException {
LOGGER.debug("Literal Data Packet at depth " + metadata.depth + " encountered");
syntaxVerifier.next(InputSymbol.LiteralData);
syntaxVerifier.next(InputSymbol.LITERAL_DATA);
PGPLiteralData literalData = packetInputStream.readLiteralData();
// Extract Metadata
this.metadata.setChild(new MessageMetadata.LiteralData(
@ -354,7 +354,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
}
private void processCompressedData() throws IOException, PGPException {
syntaxVerifier.next(InputSymbol.CompressedData);
syntaxVerifier.next(InputSymbol.COMPRESSED_DATA);
signatures.enterNesting();
PGPCompressedData compressedData = packetInputStream.readCompressedData();
// Extract Metadata
@ -368,7 +368,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
}
private void processOnePassSignature() throws PGPException, IOException {
syntaxVerifier.next(InputSymbol.OnePassSignature);
syntaxVerifier.next(InputSymbol.ONE_PASS_SIGNATURE);
PGPOnePassSignature onePassSignature = packetInputStream.readOnePassSignature();
LOGGER.debug("One-Pass-Signature Packet by key " + KeyIdUtil.formatKeyId(onePassSignature.getKeyID()) +
" at depth " + metadata.depth + " encountered");
@ -377,8 +377,8 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
private void processSignature() throws PGPException, IOException {
// true if Signature corresponds to OnePassSignature
boolean isSigForOPS = syntaxVerifier.peekStack() == StackSymbol.ops;
syntaxVerifier.next(InputSymbol.Signature);
boolean isSigForOPS = syntaxVerifier.peekStack() == StackSymbol.OPS;
syntaxVerifier.next(InputSymbol.SIGNATURE);
PGPSignature signature;
try {
signature = packetInputStream.readSignature();
@ -404,7 +404,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
private boolean processEncryptedData() throws IOException, PGPException {
LOGGER.debug("Symmetrically Encrypted Data Packet at depth " + metadata.depth + " encountered");
syntaxVerifier.next(InputSymbol.EncryptedData);
syntaxVerifier.next(InputSymbol.ENCRYPTED_DATA);
PGPEncryptedDataList encDataList = packetInputStream.readEncryptedDataList();
if (!encDataList.isIntegrityProtected()) {
@ -749,7 +749,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
throws IOException {
if (nestedInputStream == null) {
if (packetInputStream != null) {
syntaxVerifier.next(InputSymbol.EndOfSequence);
syntaxVerifier.next(InputSymbol.END_OF_SEQUENCE);
syntaxVerifier.assertValid();
}
return -1;
@ -780,7 +780,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
super.close();
if (closed) {
if (packetInputStream != null) {
syntaxVerifier.next(InputSymbol.EndOfSequence);
syntaxVerifier.next(InputSymbol.END_OF_SEQUENCE);
syntaxVerifier.assertValid();
}
return;
@ -799,7 +799,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
}
if (packetInputStream != null) {
syntaxVerifier.next(InputSymbol.EndOfSequence);
syntaxVerifier.next(InputSymbol.END_OF_SEQUENCE);
syntaxVerifier.assertValid();
packetInputStream.close();
}

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
}

View file

@ -21,8 +21,8 @@ public class PDATest {
@Test
public void testSimpleLiteralMessageIsValid() throws MalformedOpenPgpMessageException {
PDA check = new PDA();
check.next(InputSymbol.LiteralData);
check.next(InputSymbol.EndOfSequence);
check.next(InputSymbol.LITERAL_DATA);
check.next(InputSymbol.END_OF_SEQUENCE);
assertTrue(check.isValid());
}
@ -35,10 +35,10 @@ public class PDATest {
@Test
public void testSimpleOpsSignedMesssageIsValid() throws MalformedOpenPgpMessageException {
PDA check = new PDA();
check.next(InputSymbol.OnePassSignature);
check.next(InputSymbol.LiteralData);
check.next(InputSymbol.Signature);
check.next(InputSymbol.EndOfSequence);
check.next(InputSymbol.ONE_PASS_SIGNATURE);
check.next(InputSymbol.LITERAL_DATA);
check.next(InputSymbol.SIGNATURE);
check.next(InputSymbol.END_OF_SEQUENCE);
assertTrue(check.isValid());
}
@ -52,9 +52,9 @@ public class PDATest {
@Test
public void testSimplePrependSignedMessageIsValid() throws MalformedOpenPgpMessageException {
PDA check = new PDA();
check.next(InputSymbol.Signature);
check.next(InputSymbol.LiteralData);
check.next(InputSymbol.EndOfSequence);
check.next(InputSymbol.SIGNATURE);
check.next(InputSymbol.LITERAL_DATA);
check.next(InputSymbol.END_OF_SEQUENCE);
assertTrue(check.isValid());
}
@ -68,11 +68,11 @@ public class PDATest {
@Test
public void testOPSSignedCompressedMessageIsValid() throws MalformedOpenPgpMessageException {
PDA check = new PDA();
check.next(InputSymbol.OnePassSignature);
check.next(InputSymbol.CompressedData);
check.next(InputSymbol.ONE_PASS_SIGNATURE);
check.next(InputSymbol.COMPRESSED_DATA);
// Here would be a nested PDA for the LiteralData packet
check.next(InputSymbol.Signature);
check.next(InputSymbol.EndOfSequence);
check.next(InputSymbol.SIGNATURE);
check.next(InputSymbol.END_OF_SEQUENCE);
assertTrue(check.isValid());
}
@ -80,105 +80,105 @@ public class PDATest {
@Test
public void testOPSSignedEncryptedMessageIsValid() {
PDA check = new PDA();
check.next(InputSymbol.OnePassSignature);
check.next(InputSymbol.EncryptedData);
check.next(InputSymbol.Signature);
check.next(InputSymbol.EndOfSequence);
check.next(InputSymbol.ONE_PASS_SIGNATURE);
check.next(InputSymbol.ENCRYPTED_DATA);
check.next(InputSymbol.SIGNATURE);
check.next(InputSymbol.END_OF_SEQUENCE);
assertTrue(check.isValid());
}
@Test
public void anyInputAfterEOSIsNotValid() {
PDA check = new PDA();
check.next(InputSymbol.LiteralData);
check.next(InputSymbol.EndOfSequence);
check.next(InputSymbol.LITERAL_DATA);
check.next(InputSymbol.END_OF_SEQUENCE);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputSymbol.Signature));
() -> check.next(InputSymbol.SIGNATURE));
}
@Test
public void testEncryptedMessageWithAppendedStandaloneSigIsNotValid() {
PDA check = new PDA();
check.next(InputSymbol.EncryptedData);
check.next(InputSymbol.ENCRYPTED_DATA);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputSymbol.Signature));
() -> check.next(InputSymbol.SIGNATURE));
}
@Test
public void testOPSSignedEncryptedMessageWithMissingSigIsNotValid() {
PDA check = new PDA();
check.next(InputSymbol.OnePassSignature);
check.next(InputSymbol.EncryptedData);
check.next(InputSymbol.ONE_PASS_SIGNATURE);
check.next(InputSymbol.ENCRYPTED_DATA);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputSymbol.EndOfSequence));
() -> check.next(InputSymbol.END_OF_SEQUENCE));
}
@Test
public void testTwoLiteralDataIsNotValid() {
PDA check = new PDA();
check.next(InputSymbol.LiteralData);
check.next(InputSymbol.LITERAL_DATA);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputSymbol.LiteralData));
() -> check.next(InputSymbol.LITERAL_DATA));
}
@Test
public void testTrailingSigIsNotValid() {
PDA check = new PDA();
check.next(InputSymbol.LiteralData);
check.next(InputSymbol.LITERAL_DATA);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputSymbol.Signature));
() -> check.next(InputSymbol.SIGNATURE));
}
@Test
public void testOPSAloneIsNotValid() {
PDA check = new PDA();
check.next(InputSymbol.OnePassSignature);
check.next(InputSymbol.ONE_PASS_SIGNATURE);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputSymbol.EndOfSequence));
() -> check.next(InputSymbol.END_OF_SEQUENCE));
}
@Test
public void testOPSLitWithMissingSigIsNotValid() {
PDA check = new PDA();
check.next(InputSymbol.OnePassSignature);
check.next(InputSymbol.LiteralData);
check.next(InputSymbol.ONE_PASS_SIGNATURE);
check.next(InputSymbol.LITERAL_DATA);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputSymbol.EndOfSequence));
() -> check.next(InputSymbol.END_OF_SEQUENCE));
}
@Test
public void testCompressedMessageWithStandalongAppendedSigIsNotValid() {
PDA check = new PDA();
check.next(InputSymbol.CompressedData);
check.next(InputSymbol.COMPRESSED_DATA);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputSymbol.Signature));
() -> check.next(InputSymbol.SIGNATURE));
}
@Test
public void testOPSCompressedDataWithMissingSigIsNotValid() {
PDA check = new PDA();
check.next(InputSymbol.OnePassSignature);
check.next(InputSymbol.CompressedData);
check.next(InputSymbol.ONE_PASS_SIGNATURE);
check.next(InputSymbol.COMPRESSED_DATA);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputSymbol.EndOfSequence));
() -> check.next(InputSymbol.END_OF_SEQUENCE));
}
@Test
public void testCompressedMessageFollowedByTrailingLiteralDataIsNotValid() {
PDA check = new PDA();
check.next(InputSymbol.CompressedData);
check.next(InputSymbol.COMPRESSED_DATA);
assertThrows(MalformedOpenPgpMessageException.class,
() -> check.next(InputSymbol.LiteralData));
() -> check.next(InputSymbol.LITERAL_DATA));
}
@Test
public void testOPSWithPrependedSigIsValid() {
PDA check = new PDA();
check.next(InputSymbol.Signature);
check.next(InputSymbol.OnePassSignature);
check.next(InputSymbol.LiteralData);
check.next(InputSymbol.Signature);
check.next(InputSymbol.EndOfSequence);
check.next(InputSymbol.SIGNATURE);
check.next(InputSymbol.ONE_PASS_SIGNATURE);
check.next(InputSymbol.LITERAL_DATA);
check.next(InputSymbol.SIGNATURE);
check.next(InputSymbol.END_OF_SEQUENCE);
assertTrue(check.isValid());
}
@ -186,11 +186,11 @@ public class PDATest {
@Test
public void testPrependedSigInsideOPSSignedMessageIsValid() {
PDA check = new PDA();
check.next(InputSymbol.OnePassSignature);
check.next(InputSymbol.Signature);
check.next(InputSymbol.LiteralData);
check.next(InputSymbol.Signature);
check.next(InputSymbol.EndOfSequence);
check.next(InputSymbol.ONE_PASS_SIGNATURE);
check.next(InputSymbol.SIGNATURE);
check.next(InputSymbol.LITERAL_DATA);
check.next(InputSymbol.SIGNATURE);
check.next(InputSymbol.END_OF_SEQUENCE);
assertTrue(check.isValid());
}