brontide: remove handshake helper function

Move the functionality directly into completeHandshake instead. If a
failure does happen at any point during the handshake, it is beneficial
to know which line it happens on for debugging. The helper function was
hiding this information.
This commit is contained in:
Matt Morehouse 2023-04-18 10:45:01 -05:00
parent 6397497bb6
commit eb31d47094
No known key found for this signature in database
GPG key ID: CC8ECA224831C982

View file

@ -59,43 +59,35 @@ var (
// and completes the brontide handshake between them. If any part of the
// handshake fails, this function will panic.
func completeHandshake(t *testing.T, initiator, responder *Machine) {
t.Helper()
if err := handshake(initiator, responder); err != nil {
dumpAndFail(t, initiator, responder, err)
}
}
// handshake actually completes the brontide handshake and bubbles up
// an error to the calling function.
func handshake(initiator, responder *Machine) error {
// Generate ActOne and send to the responder.
actOne, err := initiator.GenActOne()
if err != nil {
return err
dumpAndFail(t, initiator, responder, err)
}
if err := responder.RecvActOne(actOne); err != nil {
return err
dumpAndFail(t, initiator, responder, err)
}
// Generate ActTwo and send to initiator.
actTwo, err := responder.GenActTwo()
if err != nil {
return err
dumpAndFail(t, initiator, responder, err)
}
if err := initiator.RecvActTwo(actTwo); err != nil {
return err
dumpAndFail(t, initiator, responder, err)
}
// Generate ActThree and send to responder.
actThree, err := initiator.GenActThree()
if err != nil {
return err
dumpAndFail(t, initiator, responder, err)
}
return responder.RecvActThree(actThree)
if err := responder.RecvActThree(actThree); err != nil {
dumpAndFail(t, initiator, responder, err)
}
}
// dumpAndFail dumps the initiator and responder Machines and fails.