Skip to content

ident: make Name's inner Vec private - #171

Open
pcnofelt wants to merge 1 commit into
NetSys:mainfrom
pcnofelt:name-private-field
Open

ident: make Name's inner Vec private#171
pcnofelt wants to merge 1 commit into
NetSys:mainfrom
pcnofelt:name-private-field

Conversation

@pcnofelt

@pcnofeltpcnofelt commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

What

Makes Name's inner Vec<String> private.
Addresses linear issue IM-55

Why

Name assumes it always has at least one label. FromStr enforces that, but the public tuple field let callers write Name(vec![]) directly and bypass validation, which could lead to a runtime panic in helpers like first_label(). Making the field private closes that gap, so the invariant holds by construction.

Changes

  • src/ident.rs: make the inner Vec private and switch first_label() from expect() to the local assert() helper.
  • src/modules/adhoc.rs: use label_count() instead of reading .0 directly.
  • src/trust_engine_bench/node.rs: build derived names through parsing instead of pushing onto the raw Vec.
  • context/interfaces/src/ident.md: document Name as opaque.

After this change, code outside src/ident.rs no longer constructs Name(...) or reads .0.

🤖 Generated with Claude Code

Make Name's inner Vec private so callers can't construct an empty Name and break the invariant that name helpers like first_label() rely on. FromStr already enforces this; the public tuple field was the only way to bypass it.
Update the code that was still reaching into the tuple field to build names by parsing instead, refresh the interface doc to describe Name as opaque, and switch first_label() to the local assert() helper for this invariant.
@pcnofelt
pcnofelt requested a review from ejjJune 24, 2026 05:34
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@pcnofelt