38// Exported error sentinels returned by ValidateNymFormat. Use
39// errors.Is or direct equality; do not string-match.
40//
41// ErrReservedPrefix's message is built from reservedPrefixes at package
42// init time so the surfaced list never drifts from the actual policy.
43//
44// Canonical-collision detection moved to r/sys/users in Option B.
45// Consumers that previously caught namereg.ErrCanonicalCollision
46// should switch to susers.ErrCanonicalCollision.
47var (
48 ErrInvalidFormat = errors.New("namereg: name must match nym-[a-z]{5,13}\\d{3}")
49 ErrReservedPrefix = errors.New("namereg: stem starts with a reserved prefix (" + strings.Join(reservedPrefixes, "/") + ")")
50 ErrBlacklisted = errors.New("namereg: stem matches a reserved role name")
51)
52
53// IsReserved reports whether the given alpha stem matches a reserved
54// role name (with implicit `s`-suffix expansion). The check is
55// canonicalized — so `vital1k`-style l-substituted variants of a
56// reserved name are also caught. O(1) backed by `reservedSet` built
57// in init().
58func IsReserved(stem string) bool {
59 _, found := reservedSet[Canonicalize(stem)]
60return found
61}
62
63// ValidateNymFormat checks the regex, prefix-exclusion, and reserved-
64// name rules in that order. Returns one of the exported sentinel
65// errors per failure mode, or nil on success.
66//
67// Does NOT run the canonical-collision check — that lives in r/sys/users
68// (susers.IsCanonicalTaken or, atomically with the write, inside
69// susers.RegisterUser).
70func ValidateNymFormat(username string) error {
71if !reNym.MatchString(username) {
72return ErrInvalidFormat
73 }
74
75// Stem is everything between `nym-` (4 chars) and the trailing
76// 3 digits. Regex guarantees 5..13 alpha chars in this slice.
77 stem := username[4 : len(username)-3]
78
79for _, p := range reservedPrefixes {
80if strings.HasPrefix(stem, p) {
81return ErrReservedPrefix
82 }
83 }
84
85if IsReserved(stem) {
86return ErrBlacklisted
87 }
88
89returnnil
90}
91
92// IsPaused exposes the realm's pause flag for cross-controller
93// coordination.
94func IsPaused() bool {
95return paused
96}
97
vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.