From 6fc5935631991355db36ae0cf6e2333f10549053 Mon Sep 17 00:00:00 2001 From: anweiss <2326106+anweiss@users.noreply.github.com> Date: Mon, 3 Oct 2022 11:58:44 -0400 Subject: [PATCH] fix #139 in cbor validator --- src/validator/cbor.rs | 824 ++++++++++++++++++++++++++---------------- 1 file changed, 513 insertions(+), 311 deletions(-) diff --git a/src/validator/cbor.rs b/src/validator/cbor.rs index 35901050..ef0f565e 100644 --- a/src/validator/cbor.rs +++ b/src/validator/cbor.rs @@ -2295,397 +2295,599 @@ where } Value::Array(_) => self.validate_array_items(&ArrayItemToken::Identifier(ident)), Value::Map(m) => { - if let Some(occur) = &self.occurrence { - let mut errors = Vec::new(); - - if is_ident_string_data_type(self.cddl, ident) { - let values_to_validate = m - .iter() - .filter_map(|(k, v)| { - if let Some(keys) = &self.validated_keys { - if !keys.contains(k) { - if matches!(k, Value::Text(_)) { - Some(v.clone()) + match &self.occurrence { + #[cfg(feature = "ast-span")] + Some(Occur::Optional(_)) | None => { + if is_ident_string_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Text(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + + return Ok(()); + } + + if is_ident_integer_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Integer(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } + + if is_ident_bool_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Bool(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } + + if is_ident_null_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Null)) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } + + if is_ident_byte_string_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Bytes(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } + + if is_ident_float_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Null)) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } + + if token::lookup_ident(ident.ident) + .in_standard_prelude() + .is_some() + { + self.add_error(format!( + "expected object value of type {}, got object", + ident.ident + )); + return Ok(()); + } + + self.visit_value(&token::Value::TEXT(ident.ident.into())) + } + #[cfg(not(feature = "ast-span"))] + Some(Occur::Optiona) | None => { + if is_ident_string_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Text(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + + return Ok(()); + } + + if is_ident_integer_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Integer(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } + + if is_ident_bool_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Bool(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } + + if is_ident_null_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Null)) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } + + if is_ident_byte_string_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Bytes(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } + + if is_ident_float_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Null)) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } + + if token::lookup_ident(ident.ident) + .in_standard_prelude() + .is_some() + { + self.add_error(format!( + "expected object value of type {}, got object", + ident.ident + )); + return Ok(()); + } + + self.visit_value(&token::Value::TEXT(ident.ident.into())) + } + Some(occur) => { + let mut errors = Vec::new(); + + if is_ident_string_data_type(self.cddl, ident) { + let values_to_validate = m + .iter() + .filter_map(|(k, v)| { + if let Some(keys) = &self.validated_keys { + if !keys.contains(k) { + if matches!(k, Value::Text(_)) { + Some(v.clone()) + } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); + None + } } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); None } + } else if matches!(k, Value::Text(_)) { + Some(v.clone()) } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); None } - } else if matches!(k, Value::Text(_)) { - Some(v.clone()) - } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); - None - } - }) - .collect::>(); - - self.values_to_validate = Some(values_to_validate); - } - - if is_ident_integer_data_type(self.cddl, ident) { - let mut errors = Vec::new(); - let values_to_validate = m - .iter() - .filter_map(|(k, v)| { - if let Some(keys) = &self.validated_keys { - if !keys.contains(k) { - if matches!(k, Value::Integer(_)) { - Some(v.clone()) + }) + .collect::>(); + + self.values_to_validate = Some(values_to_validate); + } + + if is_ident_integer_data_type(self.cddl, ident) { + let mut errors = Vec::new(); + let values_to_validate = m + .iter() + .filter_map(|(k, v)| { + if let Some(keys) = &self.validated_keys { + if !keys.contains(k) { + if matches!(k, Value::Integer(_)) { + Some(v.clone()) + } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); + None + } } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); None } + } else if matches!(k, Value::Integer(_)) { + Some(v.clone()) } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); None } - } else if matches!(k, Value::Integer(_)) { - Some(v.clone()) - } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); - None - } - }) - .collect::>(); - - self.values_to_validate = Some(values_to_validate); - } - - if is_ident_bool_data_type(self.cddl, ident) { - let mut errors = Vec::new(); - let values_to_validate = m - .iter() - .filter_map(|(k, v)| { - if let Some(keys) = &self.validated_keys { - if !keys.contains(k) { - if matches!(k, Value::Bool(_)) { - Some(v.clone()) + }) + .collect::>(); + + self.values_to_validate = Some(values_to_validate); + } + + if is_ident_bool_data_type(self.cddl, ident) { + let mut errors = Vec::new(); + let values_to_validate = m + .iter() + .filter_map(|(k, v)| { + if let Some(keys) = &self.validated_keys { + if !keys.contains(k) { + if matches!(k, Value::Bool(_)) { + Some(v.clone()) + } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); + None + } } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); None } + } else if matches!(k, Value::Bool(_)) { + Some(v.clone()) } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); None } - } else if matches!(k, Value::Bool(_)) { - Some(v.clone()) - } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); - None - } - }) - .collect::>(); - - self.values_to_validate = Some(values_to_validate); - } - - if is_ident_byte_string_data_type(self.cddl, ident) { - let mut errors = Vec::new(); - let values_to_validate = m - .iter() - .filter_map(|(k, v)| { - if let Some(keys) = &self.validated_keys { - if !keys.contains(k) { - if matches!(k, Value::Bytes(_)) { - Some(v.clone()) + }) + .collect::>(); + + self.values_to_validate = Some(values_to_validate); + } + + if is_ident_byte_string_data_type(self.cddl, ident) { + let mut errors = Vec::new(); + let values_to_validate = m + .iter() + .filter_map(|(k, v)| { + if let Some(keys) = &self.validated_keys { + if !keys.contains(k) { + if matches!(k, Value::Bytes(_)) { + Some(v.clone()) + } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); + None + } } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); None } + } else if matches!(k, Value::Bytes(_)) { + Some(v.clone()) } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); None } - } else if matches!(k, Value::Bytes(_)) { - Some(v.clone()) - } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); - None - } - }) - .collect::>(); - - self.values_to_validate = Some(values_to_validate); - } - - if is_ident_null_data_type(self.cddl, ident) { - let mut errors = Vec::new(); - let values_to_validate = m - .iter() - .filter_map(|(k, v)| { - if let Some(keys) = &self.validated_keys { - if !keys.contains(k) { - if matches!(k, Value::Null) { - Some(v.clone()) + }) + .collect::>(); + + self.values_to_validate = Some(values_to_validate); + } + + if is_ident_null_data_type(self.cddl, ident) { + let mut errors = Vec::new(); + let values_to_validate = m + .iter() + .filter_map(|(k, v)| { + if let Some(keys) = &self.validated_keys { + if !keys.contains(k) { + if matches!(k, Value::Null) { + Some(v.clone()) + } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); + None + } } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); None } + } else if matches!(k, Value::Null) { + Some(v.clone()) } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); None } - } else if matches!(k, Value::Null) { - Some(v.clone()) - } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); - None - } - }) - .collect::>(); - - self.values_to_validate = Some(values_to_validate); - } - - if is_ident_float_data_type(self.cddl, ident) { - let mut errors = Vec::new(); - let values_to_validate = m - .iter() - .filter_map(|(k, v)| { - if let Some(keys) = &self.validated_keys { - if !keys.contains(k) { - if matches!(k, Value::Float(_)) { - Some(v.clone()) + }) + .collect::>(); + + self.values_to_validate = Some(values_to_validate); + } + + if is_ident_float_data_type(self.cddl, ident) { + let mut errors = Vec::new(); + let values_to_validate = m + .iter() + .filter_map(|(k, v)| { + if let Some(keys) = &self.validated_keys { + if !keys.contains(k) { + if matches!(k, Value::Float(_)) { + Some(v.clone()) + } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); + None + } } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); None } + } else if matches!(k, Value::Float(_)) { + Some(v.clone()) } else { + errors.push(format!("key of type {} required, got {:?}", ident, k)); None } - } else if matches!(k, Value::Float(_)) { - Some(v.clone()) - } else { - errors.push(format!("key of type {} required, got {:?}", ident, k)); - None - } - }) - .collect::>(); - - self.values_to_validate = Some(values_to_validate); - } + }) + .collect::>(); - // If key validation error occurs, return early before checking occurrences - if !errors.is_empty() { - for e in errors.into_iter() { - self.add_error(e); + self.values_to_validate = Some(values_to_validate); } - return Ok(()); - } - - #[cfg(feature = "ast-span")] - if let Occur::ZeroOrMore(_) | Occur::OneOrMore(_) = occur { - if let Occur::OneOrMore(_) = occur { - if m.is_empty() { - self.add_error(format!( - "map cannot be empty, one or more entries with key type {} required", - ident - )); - return Ok(()); + // If key validation error occurs, return early before checking occurrences + if !errors.is_empty() { + for e in errors.into_iter() { + self.add_error(e); } + + return Ok(()); } - } else if let Occur::Exact { lower, upper, .. } = occur { - if let Some(values_to_validate) = &self.values_to_validate { - if let Some(lower) = lower { - if let Some(upper) = upper { - if values_to_validate.len() < *lower || values_to_validate.len() > *upper { - if lower == upper { - self.add_error(format!( - "object must contain exactly {} entries of key of type {}", - lower, ident, - )); - } else { - self.add_error(format!( - "object must contain between {} and {} entries of key of type {}", - lower, upper, ident, - )); + + #[cfg(feature = "ast-span")] + if let Occur::ZeroOrMore(_) | Occur::OneOrMore(_) = occur { + if let Occur::OneOrMore(_) = occur { + if m.is_empty() { + self.add_error(format!( + "map cannot be empty, one or more entries with key type {} required", + ident + )); + return Ok(()); + } + } + } else if let Occur::Exact { lower, upper, .. } = occur { + if let Some(values_to_validate) = &self.values_to_validate { + if let Some(lower) = lower { + if let Some(upper) = upper { + if values_to_validate.len() < *lower || values_to_validate.len() > *upper { + if lower == upper { + self.add_error(format!( + "object must contain exactly {} entries of key of type {}", + lower, ident, + )); + } else { + self.add_error(format!( + "object must contain between {} and {} entries of key of type {}", + lower, upper, ident, + )); + } + + return Ok(()); } + } + + if values_to_validate.len() < *lower { + self.add_error(format!( + "object must contain at least {} entries of key of type {}", + lower, ident, + )); return Ok(()); } } - if values_to_validate.len() < *lower { - self.add_error(format!( - "object must contain at least {} entries of key of type {}", - lower, ident, - )); + if let Some(upper) = upper { + if values_to_validate.len() > *upper { + self.add_error(format!( + "object must contain no more than {} entries of key of type {}", + upper, ident, + )); - return Ok(()); + return Ok(()); + } } + + return Ok(()); } + } - if let Some(upper) = upper { - if values_to_validate.len() > *upper { + #[cfg(not(feature = "ast-span"))] + if let Occur::ZeroOrMore | Occur::OneOrMore = occur { + if let Occur::OneOrMore = occur { + if o.is_empty() { self.add_error(format!( - "object must contain no more than {} entries of key of type {}", - upper, ident, + "object cannot be empty, one or more entries with key type {} required", + ident )); - return Ok(()); } } + } else if let Occur::Exact { lower, upper } = occur { + if let Some(values_to_validate) = &self.values_to_validate { + if let Some(lower) = lower { + if let Some(upper) = upper { + if values_to_validate.len() < *lower || values_to_validate.len() > *upper { + if lower == upper { + self.add_error(format!( + "object must contain exactly {} entries of key of type {}", + lower, ident, + )); + } else { + self.add_error(format!( + "object must contain between {} and {} entries of key of type {}", + lower, upper, ident, + )); + } - return Ok(()); - } - } - - #[cfg(not(feature = "ast-span"))] - if let Occur::ZeroOrMore | Occur::OneOrMore = occur { - if let Occur::OneOrMore = occur { - if o.is_empty() { - self.add_error(format!( - "object cannot be empty, one or more entries with key type {} required", - ident - )); - return Ok(()); - } - } - } else if let Occur::Exact { lower, upper } = occur { - if let Some(values_to_validate) = &self.values_to_validate { - if let Some(lower) = lower { - if let Some(upper) = upper { - if values_to_validate.len() < *lower || values_to_validate.len() > *upper { - if lower == upper { - self.add_error(format!( - "object must contain exactly {} entries of key of type {}", - lower, ident, - )); - } else { - self.add_error(format!( - "object must contain between {} and {} entries of key of type {}", - lower, upper, ident, - )); + return Ok(()); } + } + + if values_to_validate.len() < *lower { + self.add_error(format!( + "object must contain at least {} entries of key of type {}", + lower, ident, + )); return Ok(()); } } - if values_to_validate.len() < *lower { - self.add_error(format!( - "object must contain at least {} entries of key of type {}", - lower, ident, - )); + if let Some(upper) = upper { + if values_to_validate.len() > *upper { + self.add_error(format!( + "object must contain no more than {} entries of key of type {}", + upper, ident, + )); - return Ok(()); + return Ok(()); + } } - } - if let Some(upper) = upper { - if values_to_validate.len() > *upper { - self.add_error(format!( - "object must contain no more than {} entries of key of type {}", - upper, ident, - )); + return Ok(()); + } + } - return Ok(()); - } + if is_ident_string_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Text(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); } return Ok(()); } - } - } - if is_ident_string_data_type(self.cddl, ident) && !self.validating_value { - if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Text(_))) { - self - .validated_keys - .get_or_insert(vec![k.clone()]) - .push(k.clone()); - self.object_value = Some(v.clone()); - let _ = write!(self.cbor_location, "/{:?}", v); - } else { - self.add_error(format!("map requires entry key of type {}", ident)); - } + if is_ident_integer_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Integer(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } - return Ok(()); - } + if is_ident_bool_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Bool(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } - if is_ident_integer_data_type(self.cddl, ident) && !self.validating_value { - if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Integer(_))) { - self - .validated_keys - .get_or_insert(vec![k.clone()]) - .push(k.clone()); - self.object_value = Some(v.clone()); - let _ = write!(self.cbor_location, "/{:?}", v); - } else { - self.add_error(format!("map requires entry key of type {}", ident)); - } - return Ok(()); - } + if is_ident_null_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Null)) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } - if is_ident_bool_data_type(self.cddl, ident) && !self.validating_value { - if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Bool(_))) { - self - .validated_keys - .get_or_insert(vec![k.clone()]) - .push(k.clone()); - self.object_value = Some(v.clone()); - let _ = write!(self.cbor_location, "/{:?}", v); - } else { - self.add_error(format!("map requires entry key of type {}", ident)); - } - return Ok(()); - } + if is_ident_byte_string_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Bytes(_))) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } - if is_ident_null_data_type(self.cddl, ident) && !self.validating_value { - if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Null)) { - self - .validated_keys - .get_or_insert(vec![k.clone()]) - .push(k.clone()); - self.object_value = Some(v.clone()); - let _ = write!(self.cbor_location, "/{:?}", v); - } else { - self.add_error(format!("map requires entry key of type {}", ident)); - } - return Ok(()); - } + if is_ident_float_data_type(self.cddl, ident) && !self.validating_value { + if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Null)) { + self + .validated_keys + .get_or_insert(vec![k.clone()]) + .push(k.clone()); + self.object_value = Some(v.clone()); + let _ = write!(self.cbor_location, "/{:?}", v); + } else { + self.add_error(format!("map requires entry key of type {}", ident)); + } + return Ok(()); + } - if is_ident_byte_string_data_type(self.cddl, ident) && !self.validating_value { - if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Bytes(_))) { - self - .validated_keys - .get_or_insert(vec![k.clone()]) - .push(k.clone()); - self.object_value = Some(v.clone()); - let _ = write!(self.cbor_location, "/{:?}", v); - } else { - self.add_error(format!("map requires entry key of type {}", ident)); - } - return Ok(()); - } + if token::lookup_ident(ident.ident) + .in_standard_prelude() + .is_some() + { + self.add_error(format!( + "expected object value of type {}, got object", + ident.ident + )); + return Ok(()); + } - if is_ident_float_data_type(self.cddl, ident) && !self.validating_value { - if let Some((k, v)) = m.iter().find(|(k, _)| matches!(k, Value::Null)) { - self - .validated_keys - .get_or_insert(vec![k.clone()]) - .push(k.clone()); - self.object_value = Some(v.clone()); - let _ = write!(self.cbor_location, "/{:?}", v); - } else { - self.add_error(format!("map requires entry key of type {}", ident)); + self.visit_value(&token::Value::TEXT(ident.ident.into())) } - return Ok(()); - } - - if token::lookup_ident(ident.ident) - .in_standard_prelude() - .is_some() - { - self.add_error(format!( - "expected object value of type {}, got object", - ident.ident - )); - return Ok(()); } - - self.visit_value(&token::Value::TEXT(ident.ident.into())) } _ => { if let Some(cut_value) = self.cut_value.take() {