Three more unwrap_or(HashAlg::Sha256) sites default an empty algorithm list, not an ambiguous digest length
- Dominant language
- Rust
- Stars
- 3
- Forks
- 0
- Avg merge
- 1d 42m
- Merged PRs (30d)
- 11
Description
## Summary
While closing issue #15 (a digest-length-inference site silently defaulting to SHA-256 instead of erroring), a related but distinct pattern was found at three more call sites. These don't infer an algorithm from an ambiguous digest length — they default to SHA-256 whenever an active-algorithm list happens to be empty:
- `rs/cyphr/src/state.rs:478` — `algs.first().copied().unwrap_or(HashAlg::Sha256)`
- `rs/cyphr/src/principal.rs:888` — `self.active_algs().first().copied().unwrap_or(HashAlg::Sha256)`
- `rs/cyphr/src/principal.rs:1843` — `active_algs.first().copied().unwrap_or(HashAlg::Sha256)`
## Why this is a separate concern from #15/#51
The fix that landed for #15 (`rs/cyphr/src/state.rs:776`, `compute_dr`) addressed inferring a source algorithm from a digest's byte length — a case where the input is ambiguous and defaulting silently masks malformed data. These three sites are structurally different: they're picking a *fallback* algorithm when a principal's own active-algorithm list is empty, which may or may not be a state that can legitimately arise (a principal always active in some algorithm in ordinary operation) or may already be guarded against elsewhere. Whether SHA-256 is a reasonable, deliberate default here — or whether an empty list at these call sites should itself be treated as an error — needs its own look rather than being folded into the digest-length fix.
## Not investigated further
This was flagged in passing while working a different, narrowly-scoped node; whether any of these three sites can actually be reached with an empty algorithm list in practice (and what the correct behavior should be if so) is unresolved.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading rs/cyphr/src/state.rs:478 and rs/cyphr/src/principal.rs:888 and 1843, then trace active-algorithm list construction and any guards around these call sites. Determine whether an empty list is reachable and whether SHA-256 is an intentional fallback or should produce an error. Done means the behavior is decided consistently and covered by relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cryptography, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100