Define separate SignedStatement & UnsignedStatement classes #179
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This refactors the Statement class hierarchy a bit to make a clean split between signed and unsigned statements.
There's now a base
Statement
class that has everything except thesignature
field, plus common helper methods like.toProtobuf
,.expandObjects
, etc.The
UnsignedStatement
subclass adds the.calculateSignature
and.sign
methods, which returnBuffer
andSignedStatement
, respectively.The
SignedStatement
class has thesignature
field and the.verifySignature
method. BothSignedStatement
andUnsignedStatement
inherit fromStatement
directly, soSignedStatement
does not have the.sign
and.calculateSignature
methods. However, there's a helper on the the base class.asUnsignedStatement()
that will return an unsigned copy of either a signed or unsigned statement. So, if you need to strip an existing signature and re-sign a message, you can do:Converting from protobuf still happens with
Statement.fromProtobuf()
, which will return aSignedStatement
if the protobuf message has asignature
, and anUnsignedStatement
otherwise.