Files

40 lines
1.3 KiB
Go

// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package xorg
import (
"context"
"io"
"runtime"
"git.stormux.org/storm/cthulhu/internal/remoteinput"
)
type remoteHelperTarget struct{ target *remoteKeyTarget }
func (target remoteHelperTarget) Apply(name string, pressed bool) error {
return target.target.apply(name, pressed)
}
func (target remoteHelperTarget) Close() error { return target.target.close() }
// ServeRemoteKeyHelper is for the independent source-built helper executable,
// never the reader event loop. It supplies no consent or production mailbox
// attachment. Physical collision/provenance and native policy gates remain open.
func ServeRemoteKeyHelper(ctx context.Context, epoch uint64, control, lifetime io.ReadCloser, output io.WriteCloser) error {
if epoch == 0 || ctx == nil || ctx.Err() != nil || control == nil || lifetime == nil || output == nil {
return remoteinput.ErrProtocol
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
target, err := openRemoteKeyTarget()
if err != nil {
control.Close()
lifetime.Close()
output.Close()
return remoteinput.ErrTarget
}
return remoteinput.Run(ctx, epoch, control, lifetime, output, remoteHelperTarget{target: target})
}