package auth import ( "encoding/json" "time" "github.com/google/uuid" ) // nowFn is the clock for TOTP validation. It is a variable so a test can pin time; production uses // the wall clock. Session expiry math runs on the database clock, not this one. var nowFn = time.Now func reasonJSON(reason string) []byte { b, _ := json.Marshal(map[string]string{"reason": reason}) return b } func reasonRole(role string) []byte { b, _ := json.Marshal(map[string]string{"role": role}) return b } func nullStr(s string) *string { if s == "" { return nil } return &s } // mustUUID parses a uuid that originates from validated server state (a session row), where it is // always well formed. An unparseable value yields uuid.Nil, which matches no real row. func mustUUID(s string) uuid.UUID { id, err := uuid.Parse(s) if err != nil { return uuid.Nil } return id } func orgPtr(s string) *uuid.UUID { if s == "" { return nil } id, err := uuid.Parse(s) if err != nil { return nil } return &id }