Skip to content
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

Add new API for extracting the underling CBOR value from a CBORValidator for reuse #217

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/validator/cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@
}
}

/// Extract the underlying CBOR Value.
pub fn extract_cbor(self) -> Value {
self.cbor
}

fn validate_array_items<T: std::fmt::Debug + 'static>(
&mut self,
token: &ArrayItemToken,
Expand Down Expand Up @@ -1021,7 +1026,7 @@
} = controller
{
if let Some(name) = self.eval_generic_rule {
if let Some(gr) = self

Check warning on line 1029 in src/validator/cbor.rs

View workflow job for this annotation

GitHub Actions / wasm style linting (stable)

unnecessarily eager cloning of iterator items

Check warning on line 1029 in src/validator/cbor.rs

View workflow job for this annotation

GitHub Actions / Style linting (stable)

unnecessarily eager cloning of iterator items
.generic_rules
.iter()
.cloned()
Expand All @@ -1045,7 +1050,7 @@
}

if let Some(name) = self.eval_generic_rule {
if let Some(gr) = self

Check warning on line 1053 in src/validator/cbor.rs

View workflow job for this annotation

GitHub Actions / wasm style linting (stable)

unnecessarily eager cloning of iterator items

Check warning on line 1053 in src/validator/cbor.rs

View workflow job for this annotation

GitHub Actions / Style linting (stable)

unnecessarily eager cloning of iterator items
.generic_rules
.iter()
.cloned()
Expand Down Expand Up @@ -2210,7 +2215,7 @@

fn visit_identifier(&mut self, ident: &Identifier<'a>) -> visitor::Result<Error<T>> {
if let Some(name) = self.eval_generic_rule {
if let Some(gr) = self

Check warning on line 2218 in src/validator/cbor.rs

View workflow job for this annotation

GitHub Actions / wasm style linting (stable)

unnecessarily eager cloning of iterator items

Check warning on line 2218 in src/validator/cbor.rs

View workflow job for this annotation

GitHub Actions / Style linting (stable)

unnecessarily eager cloning of iterator items
.generic_rules
.iter()
.cloned()
Expand Down Expand Up @@ -3903,4 +3908,14 @@

Ok(())
}

#[test]
fn extract_cbor() {
use ciborium::value::Value;

let cbor = Value::Float(1.23);
let cddl = cddl_from_str("start = any", true).unwrap();
let cv = CBORValidator::new(&cddl, cbor, None);
assert_eq!(cv.extract_cbor(), Value::Float(1.23));
}
}
Loading