From a748d40745611b471ee2a8dd79656aaa174eb03c Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 19 Feb 2025 00:25:00 +0900 Subject: app: store values with string representation Improves code readability without changing memory layout. Signed-off-by: Ophestra --- internal/app/app.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'internal/app/app.go') diff --git a/internal/app/app.go b/internal/app/app.go index cf21ac71..aa798af6 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -1,6 +1,7 @@ package app import ( + "fmt" "sync" "git.gensokyo.uk/security/fortify/fst" @@ -10,14 +11,18 @@ import ( func New(os sys.State) (fst.App, error) { a := new(app) - a.id = new(fst.ID) a.os = os - return a, fst.NewAppID(a.id) + + id := new(fst.ID) + err := fst.NewAppID(id) + a.id = newID(id) + + return a, err } type app struct { // application unique identifier - id *fst.ID + id *stringPair[fst.ID] // operating system interface os sys.State // shim process manager @@ -28,13 +33,11 @@ type app struct { lock sync.RWMutex } -func (a *app) ID() fst.ID { - return *a.id -} +func (a *app) ID() fst.ID { return a.id.unwrap() } func (a *app) String() string { if a == nil { - return "(invalid fortified app)" + return "(invalid app)" } a.lock.RLock() @@ -45,8 +48,11 @@ func (a *app) String() string { } if a.seal != nil { - return "(sealed fortified app as uid " + a.seal.sys.user.us + ")" + if a.seal.sys.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.seal.sys.user.uid) } - return "(unsealed fortified app)" + return fmt.Sprintf("(unsealed app %s)", a.id) } -- cgit v1.3.1