Skip to content

Commit

Permalink
MessagePayload: derive signed from signedBy
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomlneto committed Mar 3, 2025
1 parent dd85b79 commit 142c518
Showing 1 changed file with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
package byzzbench.simulator.transport;

import java.io.Serializable;

import lombok.Getter;

import java.io.Serializable;

/**
* Interface for the payload of a {@link MessageEvent}.
*/
@Getter
public abstract class MessagePayload implements Serializable {
// Could be removed as we can just check
// signedBy != null
private boolean signed;
private String signedBy;

/**
* A string representation of the message type.
*/
public abstract String getType();


/*
* Dummy function to validate the signature of the
* message instance. Returns true if the message was
* signed by @param id.
*/
public boolean isSignedBy(String id) {
return this.signed && this.signedBy.equals(id);
}

/*
* Dummy function to sign the message with the public
* key of the @param sender.
*/
public void sign(String sender) {
this.signed = true;
this.signedBy = sender;
}
private String signedBy;

/**
* A string representation of the message type.
*/
public abstract String getType();


/*
* Dummy function to validate the signature of the
* message instance. Returns true if the message was
* signed by @param id.
*/
public boolean isSignedBy(String id) {
return this.isSigned() && this.signedBy.equals(id);
}

/*
* Dummy function to sign the message with the public
* key of the @param sender.
*/
public void sign(String sender) {
this.signedBy = sender;
}

public boolean isSigned() {
return this.signedBy != null;
}
}

0 comments on commit 142c518

Please sign in to comment.