| 591 | } |
| 592 | |
| 593 | fn sanitize_denials_by_group<I>(denials_by_group: I) -> Option<BTreeMap<DenyGroup, u64>> |
| 594 | where |
| 595 | I: IntoIterator<Item = (DenyGroup, u64)>, |
| 596 | { |
| 597 | let mut sanitized = BTreeMap::<DenyGroup, u64>::new(); |
| 598 | for (group, count) in denials_by_group { |
| 599 | if !valid_count(count) { |
| 600 | return None; |
| 601 | } |
| 602 | let next_count = sanitized |
| 603 | .get(&group) |
| 604 | .copied() |
| 605 | .unwrap_or(0) |
| 606 | .checked_add(count)?; |
| 607 | if !valid_count(next_count) { |
| 608 | return None; |
| 609 | } |
| 610 | sanitized.insert(group, next_count); |
| 611 | } |
| 612 | Some(sanitized) |
| 613 | } |
| 614 | |
| 615 | #[cfg(all(test, feature = "telemetry"))] |
| 616 | mod tests { |