-
Notifications
You must be signed in to change notification settings - Fork 1
feat(rust/catalyst-types): Add report_duplicated_key and report_missing_keys functions to catalyst-types #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
stanislav-tkach
merged 6 commits into
main
from
catalyst-types-report_duplicated_key-report_missing_keys
Jan 27, 2025
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3fa3e8b
Add report_duplicated_key and report_missing_keys functions to cataly…
stanislav-tkach 371037f
Update rust/catalyst-types/src/cbor_utils.rs
stanislav-tkach 814b992
Merge branch 'main' into catalyst-types-report_duplicated_key-report_…
stanislav-tkach 6819aeb
Revert changes
stanislav-tkach 48678de
fix
stanislav-tkach 8b55825
Merge branch 'main' into catalyst-types-report_duplicated_key-report_…
stanislav-tkach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //! CBOR utilities that are highly tied to Catalyst types, so they don't belong to the | ||
| //! `cbork-utils` crate. | ||
|
|
||
| use std::fmt::Debug; | ||
|
|
||
| use crate::problem_report::ProblemReport; | ||
|
|
||
| /// Adds a "duplicated field" entry to the report and returns true if the field is already | ||
| /// present in the given found keys list. | ||
| pub fn report_duplicated_key<T: Debug + PartialEq>( | ||
| found_keys: &[T], key: &T, index: u64, context: &str, report: &ProblemReport, | ||
| ) -> bool { | ||
| if found_keys.contains(key) { | ||
| report.duplicate_field( | ||
| format!("{key:?}").as_str(), | ||
| format!("Redundant key found in item {} in RBAC map", index + 1).as_str(), | ||
| context, | ||
| ); | ||
| return true; | ||
| } | ||
| false | ||
| } | ||
|
|
||
| /// Adds a "missing field" entry to the report for every required key that isn't present | ||
| /// in the found keys list. | ||
| pub fn report_missing_keys<T: Debug + PartialEq>( | ||
| found_keys: &[T], required_keys: &[T], context: &str, report: &ProblemReport, | ||
| ) { | ||
| for key in required_keys { | ||
| if !found_keys.contains(key) { | ||
| report.missing_field(&format!("{key:?}"), context); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| //! Catalyst Generic Types | ||
|
|
||
| pub mod cbor_utils; | ||
| pub mod conversion; | ||
| pub mod hashes; | ||
| pub mod id_uri; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.