Skip to content

fix(rstix): use known() for confidence scale table literals - #637

Open
SecurityEnthusiast wants to merge 3 commits into
timescale:mainfrom
SecurityEnthusiast:fix/rstix-confidence-scale-known-values
Open

SecurityEnthusiast wants to merge 3 commits into
timescale:mainfrom
SecurityEnthusiast:fix/rstix-confidence-scale-known-values

Conversation

@SecurityEnthusiast

@SecurityEnthusiast SecurityEnthusiast commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Removes 26 production .expect("in range") calls from verbal confidence scale to_stix tables by introducing private Confidence::known() for compile-time literals in 0..=100. Public Confidence::new is unchanged.

Test plan

  • [*] cargo test -p rstix --features serde --locked confidence

Add a private const Confidence::known for compile-time scale mappings
so verbal-scale to_stix paths no longer panic via expect on in-range literals.

@mostafa mostafa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested. The 26 scale literals keep the same values, and public Confidence::new is unchanged. cargo fmt --all -- --check is clean, cargo clippy -p rstix --all-targets --all-features -- -D warnings is clean, cargo doc -p rstix --all-features --locked --no-deps is clean, and cargo test -p rstix --features serde --locked confidence passes (4 library tests, including nil_scale_examples, plus the spec confidence round-trip). Mapping High to 84 fails nil_scale_examples.

Blocker: Confidence::known builds a Confidence for any u8. See the comment on known.

Non-blocking: the changelog links point at crates/rstix/README.md, which documents neither function. See the comment on CHANGELOG.md.

CI, Docs, and Docs audit are action_required until a maintainer approves the fork workflows. This branch and #638 both insert a heading at the top of ## [Unreleased], so the second one to merge needs a rebase.


/// Construct from a compile-time-known value in `0..=100` (scale tables only).
const fn known(val: u8) -> Self {
Self(val)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

known returns Confidence(val) for every u8. Confidence::new rejects values above 100, and these to_stix arms are ordinary calls, so the compiler does not check the literals. A table entry of 101 used to panic in .expect("in range"). It now comes back as Ok(Confidence(101)).

Keep the check in the constructor:

const fn known(val: u8) -> Self {
    assert!(val <= 100);
    Self(val)
}

That panics only for an out-of-range value. With the assert, a const context rejects 101 at compile time (const BAD: u8 = known(101) is E0080). A runtime call panics when that value is used. const { Confidence::known(85) } is the form that matches the "compile-time literal" comment on this function.

Comment thread CHANGELOG.md

### rstix: confidence scale label mapping without panic sites (#637)

- Verbal confidence scales (`NiLScale`, `AdmiraltyScale`, `WepScale`, `DniScale`, `MispScale`) map known labels through private [`Confidence::known`](crates/rstix/README.md) for compile-time literals in `0..=100`, replacing `.expect("in range")` on those paths. Behavior and public [`Confidence::new`](crates/rstix/README.md) are unchanged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both links target crates/rstix/README.md. That file does not document Confidence::known or Confidence::new. Release notes include CHANGELOG.md verbatim, and from that page a relative crates/... link does not resolve.

Use backticks and drop the links: verbal confidence scales (NiLScale, AdmiraltyScale, WepScale, DniScale, MispScale) map known labels through private Confidence::known for literals in 0..=100. Public Confidence::new is unchanged.

This branch has not been deployed

No deployments
Sign up for free to 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.

2 participants