diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-04-12 13:56:41 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-04-12 13:56:41 +0900 |
| commit | 6309469e933a31a300fbf16d8e77f48dcee402d3 (patch) | |
| tree | 8f8a72ee02b3ca15b104a6e55c9379e20f8d7e8a /internal/app/setuid/app.go | |
| parent | 0d7c1a9a4356614f035225aeb24e66421879a99b (diff) | |
app/instance: wrap internal implementation
This reduces the scope of the fst package, which was growing questionably large.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/app/setuid/app.go')
| -rw-r--r-- | internal/app/setuid/app.go | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/internal/app/setuid/app.go b/internal/app/setuid/app.go deleted file mode 100644 index 472d06ea..00000000 --- a/internal/app/setuid/app.go +++ /dev/null @@ -1,82 +0,0 @@ -package setuid - -import ( - "context" - "fmt" - "log" - "sync" - - "git.gensokyo.uk/security/fortify/fst" - "git.gensokyo.uk/security/fortify/internal/fmsg" - "git.gensokyo.uk/security/fortify/internal/sys" -) - -func New(ctx context.Context, os sys.State) (fst.App, error) { - a := new(app) - a.sys = os - a.ctx = ctx - - id := new(fst.ID) - err := fst.NewAppID(id) - a.id = newID(id) - - return a, err -} - -func MustNew(ctx context.Context, os sys.State) fst.App { - a, err := New(ctx, os) - if err != nil { - log.Fatalf("cannot create app: %v", err) - } - return a -} - -type app struct { - id *stringPair[fst.ID] - sys sys.State - ctx context.Context - - *outcome - mu sync.RWMutex -} - -func (a *app) ID() fst.ID { a.mu.RLock(); defer a.mu.RUnlock(); return a.id.unwrap() } - -func (a *app) String() string { - if a == nil { - return "(invalid app)" - } - - a.mu.RLock() - defer a.mu.RUnlock() - - if a.outcome != nil { - if a.outcome.user.uid == nil { - return fmt.Sprintf("(sealed app %s with invalid uid)", a.id) - } - return fmt.Sprintf("(sealed app %s as uid %s)", a.id, a.outcome.user.uid) - } - - return fmt.Sprintf("(unsealed app %s)", a.id) -} - -func (a *app) Seal(config *fst.Config) (fst.SealedApp, error) { - a.mu.Lock() - defer a.mu.Unlock() - - if a.outcome != nil { - panic("app sealed twice") - } - if config == nil { - return nil, fmsg.WrapError(ErrConfig, - "attempted to seal app with nil config") - } - - seal := new(outcome) - seal.id = a.id - err := seal.finalise(a.ctx, a.sys, config) - if err == nil { - a.outcome = seal - } - return seal, err -} |
