Refactor HybridKexBuilder: extract shared classic-leg wiring into a private method
#18
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
HybridKexBuilder.buildInitiator()andbuildResponder()contain an identicalblock (~20 lines) that resolves the classic agreement leg based on
ClassicMode.The two methods differ only in which PQC key they require. Any future change to
the classic-leg logic (e.g. a new
ClassicModevariant, tightened validation, oradditional error context) must currently be applied twice, which is error-prone.
Why this matters
A missed update in one branch would silently produce inconsistent behavior between
initiator and responder construction — exactly the kind of asymmetry that is hard
to catch in review and leads to subtle protocol bugs.
Proposed change
Extract a private
buildClassicLeg()method containing the sharedClassicModeswitch and return the resulting
AgreementContext. BothbuildInitiator()andbuildResponder()then delegate to it before handling their respective PQC keyrequirement.
Acceptance criteria
buildClassicLeg()(or equivalently named private method) exists and is calledby both
buildInitiator()andbuildResponder().it returns.