sshpiper/cmd/sshpiperd/hook.go
Josh Bleecher Snyder 89ab72bee0
all: run gofumpt (#652)
* all: run gofumpt

https://github.com/mvdan/gofumpt

The main appeal for me here is that my (and many other peoples')
editors run this on save, so doing a single diff here
keeps other diffs minimal.

* .github/workflows: add gofumpt checker
2025-08-29 20:04:31 -07:00

36 lines
670 B
Go

package main
import "golang.org/x/crypto/ssh"
type hookChain struct {
hooks []ssh.PipePacketHook
}
// chain stops if any of the hooks return ssh.PipePacketHookReply
func (h *hookChain) append(hook ssh.PipePacketHook) {
if hook != nil {
h.hooks = append(h.hooks, hook)
}
}
func (h *hookChain) hook() ssh.PipePacketHook {
if len(h.hooks) == 0 {
return nil
}
return func(packet []byte) (method ssh.PipePacketHookMethod, packetOut []byte, err error) {
packetOut = packet
for _, hk := range h.hooks {
method, packetOut, err = hk(packetOut)
if err != nil {
return
}
if method == ssh.PipePacketHookReply {
return
}
}
return
}
}