From 60ceb324edd6e206d1dc17c9bb7345bd4e94f905 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 24 Jan 2024 12:30:36 -0500 Subject: [PATCH 1/2] Add new API for extracting the underling CBOR value from a CBORValidator for reuse. --- src/validator/cbor.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/validator/cbor.rs b/src/validator/cbor.rs index d2e424b3..45938fef 100644 --- a/src/validator/cbor.rs +++ b/src/validator/cbor.rs @@ -371,6 +371,11 @@ impl<'a> CBORValidator<'a> { } } + /// Extract the underlying CBOR Value. + pub fn extract_cbor(self) -> Value { + self.cbor + } + fn validate_array_items( &mut self, token: &ArrayItemToken, @@ -3903,4 +3908,14 @@ mod tests { 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)); + } } From 4a2d33f0f3d8ff8d4840aaa30695ece98677cac7 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 24 Jan 2024 13:10:50 -0500 Subject: [PATCH 2/2] Re-format. --- src/validator/cbor.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/validator/cbor.rs b/src/validator/cbor.rs index 45938fef..95ae83b6 100644 --- a/src/validator/cbor.rs +++ b/src/validator/cbor.rs @@ -373,7 +373,7 @@ impl<'a> CBORValidator<'a> { /// Extract the underlying CBOR Value. pub fn extract_cbor(self) -> Value { - self.cbor + self.cbor } fn validate_array_items( @@ -3911,11 +3911,11 @@ mod tests { #[test] fn extract_cbor() { - use ciborium::value::Value; + 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)); + 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)); } }