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

tdate is not defined #438

Open
dgpetrie opened this issue Jul 18, 2024 · 3 comments
Open

tdate is not defined #438

dgpetrie opened this issue Jul 18, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@dgpetrie
Copy link

RFC 8610 defines the CDDL standard prelude in appendix D. This defines tdate.
zcbor yields an exception: KeyError: 'tdate' when is is reference in CDDL.

import zcbor
cddl_str = """
date_type = {
creation: tdate
}
"""
cddl_res = zcbor.zcbor.zcbor.DataTranslator.from_cddl(cddl_str, 100)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 293, in from_cddl
my_types[my_type].post_validate()
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 937, in post_validate
none_keys = [child for child in self.value if not child.elem_has_key()]
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 937, in
none_keys = [child for child in self.value if not child.elem_has_key()]
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 928, in elem_has_key
or (self.type == "OTHER" and self.my_types[self.value].elem_has_key())
KeyError: 'tdate'

If I add the RFC8610 prelude definition of tdate the following exception is raise:

import zcbor
cddl_str = """
date_type = {
creation: tdate
}

tdate = #6.0(tstr)
"""
cddl_res = zcbor.zcbor.zcbor.DataTranslator.from_cddl(cddl_str, 100)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 293, in from_cddl
my_types[my_type].post_validate()
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 940, in post_validate
raise TypeError(
TypeError: Map member(s) must have key: [creation:OTHER'tdate'] pointing to [#6.0TSTR]

I have not tested other types defined in the RFC 8610 standard prelude. Perhaps none are defined?

@dgpetrie
Copy link
Author

The following approach for tdate does not work either:

cddl_str = """
date_type = {
creation: #6.0(tstr)
}
"""

cddl_res = zcbor.zcbor.zcbor.DataTranslator.from_cddl(cddl_str, 100)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 293, in from_cddl
my_types[my_type].post_validate()
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 940, in post_validate
raise TypeError(
TypeError: Map member(s) must have key: [creation:#6.0TSTR] pointing to []

@dgpetrie
Copy link
Author

Testing was performed in Python 3.8 using zcbor version 0.8.1

@oyvindronningstad
Copy link
Collaborator

Thanks.

The prelude is added by default when using the CLI, but not when using the Python module. The prelude can be found in the repo at zcbor/prelude.cddl, you can programmatically append it to the cddl_str. I will look into making it easier to add the when using the python module.

Your second comment seems to fail because you are defining a map, but the member has no well-formed key. Try e.g.

cddl_str = """
date_type = {
    "creation" => #6.0(tstr)
}
"""

@oyvindronningstad oyvindronningstad added the enhancement New feature or request label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants