Repository navigation
fix(rstix): use known() for confidence scale table literals - #637
SecurityEnthusiast wants to merge 3 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
|
|
||
| ### 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. |
There was a problem hiding this comment.
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.
Summary
Removes 26 production
.expect("in range")calls from verbal confidence scaleto_stixtables by introducing privateConfidence::known()for compile-time literals in0..=100. PublicConfidence::newis unchanged.Test plan
cargo test -p rstix --features serde --locked confidence