Skip to content

Fail to validate nested array #218

@gregorydemay

Description

@gregorydemay
  1. Tested with cddl = "0.9.4"
  2. Cannot handle a CDDL schema involving nested array, e.g., [0, [0]]. Note that the not-nested schema [0, 0] seems to work fine.

Example

    #[test]
    fn should_validate_nested_array() {
        let schema = r#"root = [0, 0]"#;
        let cbor_bytes = [0x82, 0x00, 0x00];
        let result = cddl::validate_cbor_from_slice(schema, &cbor_bytes, None);
        assert!( //PASSES!
            result.is_ok(),
            "Validation of {:x?} failed: {:?}",
            cbor_bytes,
            result
        );

        let schema = r#"root = [0, [0]]"#;
        let cbor_bytes = [0x82, 0x00, 0x81, 0x00];
        let result = cddl::validate_cbor_from_slice(schema, &cbor_bytes, None);
        assert!( //FAILS!
            result.is_ok(),
            "Validation of {:x?} failed: {:?}",
            cbor_bytes,
            result
        );
    }

The first assertion passes, while the second one returns the following error

Validation of [82, 0, 81, 0] failed: Err(Validation([ValidationError { reason: "expected array with length 1, got 2", cddl_location: "", cbor_location: "", is_multi_type_choice: false, is_multi_group_choice: false, is_group_to_choice_enum: false, type_group_name_entry: None }]))

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions