Internet-Draft | CDDL Module Structure | June 2023 |
Bormann | Expires 19 December 2023 | [Page] |
At the time of writing, the Concise Data Definition Language (CDDL) is defined by RFC 8610 and RFC 9165. The latter has used the extension point provided in RFC 8610, the control operator.¶
As CDDL is being used in larger projects, the need for corrections and additional features has become known that cannot be easily mapped into this single extension point. Hence, there is a need for evolution of the base CDDL specification itself.¶
The present document defines a backward- and forward-compatible way to add a module structure to CDDL.¶
Previous versions of the changes in this document were part of draft-bormann-cbor-cddl-2-draft and previously draft-bormann-cbor-cddl-freezer. This submission extracts out the functionality that is ready for further WG work.¶
This note is to be removed before publishing as an RFC.¶
The latest revision of this draft can be found at https://cbor-wg.github.io/cddl-modules/draft-ietf-cbor-cddl-modules.html. Status information for this document may be found at https://datatracker.ietf.org/doc/draft-ietf-cbor-cddl-modules/.¶
Discussion of this document takes place on the CBOR Maintenance and Extensions Working Group mailing list (mailto:cbor@ietf.org), which is archived at https://mailarchive.ietf.org/arch/browse/cbor/. Subscribe at https://www.ietf.org/mailman/listinfo/cbor/.¶
Source for this draft and an issue tracker can be found at https://github.com/cbor-wg/cddl-modules.¶
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.¶
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.¶
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."¶
This Internet-Draft will expire on 19 December 2023.¶
Copyright (c) 2023 IETF Trust and the persons identified as the document authors. All rights reserved.¶
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Revised BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Revised BSD License.¶
At the time of writing, the Concise Data Definition Language (CDDL) is defined by RFC 8610 and RFC 9165. The latter has used the extension point provided in RFC 8610, the control operator.¶
As CDDL is being used in larger projects, the need for corrections and additional features has become known that cannot be easily mapped into this single extension point. Hence, there is a need for evolution of the base CDDL specification itself.¶
The present document defines a backward- and forward-compatible way to add a module structure to CDDL.¶
Previous versions of the changes in this document were part of draft-bormann-cbor-cddl-2-draft and previously draft-bormann-cbor-cddl-freezer. This submission extracts out the functionality that is ready for further WG work.¶
Proposals for additional functionality that needs more work can be found in [I-D.bormann-cbor-cddl-2-draft]. Proposals for other additions to the CDDL specification base are in [I-D.draft-bormann-cbor-cddl-freezer].¶
The present document is intended to be the specification base of what has colloquially been called CDDL 2.0, a term hat is now focusing on module structure (other documents make up what is now called CDDL 1.1). Additional documents describe further work on CDDL.¶
The Terminology from [RFC8610] applies.¶
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.¶
bidirectional (both backward and forward)¶
Originally, CDDL was used for small data models that could be expressed in a few lines. As the size of data models that need to be expressed in CDDL has increased, the need to modularize and re-use components is increasing.¶
CDDL 1.0 has been designed with a crude form of composition: Concatenating a number of CDDL snippets creates a valid CDDL data model unless there is a name collision (identical redefinition is allowed to facilitate this approach). With larger models, managing the name space to avoid collisions becomes more pressing.¶
The knowledge which CDDL snippets need to be concatenated in order to obtain the desired data model lives entirely outside the CDDL snippets in CDDL 1.0. In CDDL 2.0, rules are packaged as modules and referenced from other modules, providing methods for control of namespace pollution.¶
Further work may be expended on unambiguous referencing into evolving specifications ("versioning") and selection of alternatives (as was emulated with snippets in Section 11 of [RFC8428]. Note that one approach for expressing variants is demonstrated in [useful] based on Section 4 of [RFC9165]). See also Section 4 of [I-D.bormann-cbor-cddl-2-draft].¶
To achieve the module structure in a way that is friendly to existing environments that operate with CDDL 1.0 snippets and CDDL 1.0 implementations, we add a super-syntax (similar to the way pragmas are often added to a language), by carrying them in what is parsed as comments in CDDL 1.0.¶
This enables each module source file to be valid CDDL\ 1 (but possibly needing to add some rule definitions imported from other source files).¶
When importing rules from other modules, there is the potential for name collisions. This is exacerbated when the modules evolve, which may lead to the introduction of a name into an imported module that is also used (likely in a different way) in the importing module.¶
To be able to manage names in such a way that collisions can be avoided, we introduce means to prepend a prefix to the names of rules being imported: the "as" clause.¶
This specification introduces directives into CDDL. A single CDDL file becomes a module by processing the (zero or more) directives in it.¶
The semantics of the module are independent of the module(s) using it, however, importing a module may involve transforming its rule names into a new namespace (Section 2.2).¶
Directives look like comments in CDDL 1, so they do not interfere with forward compatibility.¶
Lines starting with the prefix ;#
are parsed as directives in CDDL 2.0.¶
We assume that module names are filenames taken from one of several source directories available to the CDDL 2.0 processor via the environment. This avoids the need to nail down brittle pathnames or (partial?) URIs into the CDDL files.¶
The exact way how these source directories and possibly a precedence between them are established is intentionally not fully defined in this specification; it is expected that this will be specified in the context of the models just as the way they are intended to be used will be. (A more formal structure may follow later.)¶
In the CDDL 2.0 Tool described in Appendix B, the set of sources is
determined from an environment variable, CDDL_INCLUDE_PATH
, which is
modeled after usual command-line search paths.
It is a colon-separated list of pathnames to directories, with one
special feature: an empty element points to the tool's own collection.
This collection contains fragments of extracted CDDL from published
RFCs, using names such as rfc9052
.¶
(Future versions might augment this with Web extractors and/or ways to extract CDDL modules from github and from Internet-Drafts; see Appendix A.2 of [I-D.bormann-cbor-cddl-2-draft] for some design considerations.)¶
The default CDDL_INCLUDE_PATH
is:¶
.:¶
That is: files are found in the current directory (.
) and, if not
found there, cddlc’s collection.¶
In the examples following, a cddlc command line will be shown
(starting with an isolated $
sign) with the CDDL 2.0 input; the
resulting CDDL 1 will be shown separately.¶
Two groups of directives are defined at this point:¶
include
, which includes all the rules from a module (which
includes the ones imported/included there, transitively), or
specific explicitly selected rules (clause ending in "from");¶
import
, which includes only those rules from the module that are
referenced, implicitly or explicitly (clause ending in "from"), including the
rules that are referenced from these rules, transitively.¶
The include
function is more useful for composing a single model
from parts controlled by one author, while the import
function is
more about treating a module as a library:¶
The way an import
works is shown by this simple example:¶
$ cddlc -2tcddl - start = COSE_Key ;# import rfc9052¶
This results in the following CDDL 1.0 specification:¶
start = COSE_Key COSE_Key = { 1 => tstr / int, ? 2 => bstr, ? 3 => tstr / int, ? 4 => [+ tstr / int], ? 5 => bstr, * label => values, } label = int / tstr values = any¶
This is appropriate for using libraries that are well known to the importing specification. However, if it is not acceptable that the library can pollute the namespace of the importing module, the import directive can specify a namespace prefix ("as" clause):¶
$ cddlc -2tcddl - start = cose.COSE_Key ;# import rfc9052 as cose¶
This results in the following CDDL 1.0 specification:¶
start = cose.COSE_Key cose.COSE_Key = { 1 => tstr / int, ? 2 => bstr, ? 3 => tstr / int, ? 4 => [+ tstr / int], ? 5 => bstr, * cose.label => cose.values, } cose.label = int / tstr cose.values = any¶
Note how the imported names are prefixed with cose.
as specified in
the import directive, but CDDL prelude (Appendix D of [RFC8610]) names
such as tstr
and any
are not.¶
Both import
and include
directives can be augmented by an explicit
mentioning of rule names (clause ending in "from").¶
include
Starting with include
:¶
$ cddlc -2tcddl - mydata = {* label => values} ;# include label, values from rfc9052¶
With include
,
only exactly the rules mentioned are included:¶
mydata = {* label => values} label = int / tstr values = any¶
The module from which rules are explicitly imported can be namespaced:¶
$ cddlc -2tcddl - mydata = {* label => values} ;# include cose.label, cose.values from rfc9052 as cose¶
Again, only exactly the rules mentioned are included:¶
mydata = {* label => values} cose.label = int / tstr cose.values = any¶
import
Both examples would work exactly the same with import
, as the
included rules do not reference anything else from the included
module.¶
An import however also draws in the transitive closure of the rules referenced:¶
$ cddlc -2tcddl - mydata = {Fritz: cose.empty_or_serialized_map} ;# import cose.empty_or_serialized_map from rfc9052 as cose¶
The transitive closure of the rules mentioned is included:¶
mydata = {"Fritz" => cose.empty_or_serialized_map} cose.empty_or_serialized_map = bstr .cbor cose.header_map / bstr .size 0 cose.header_map = { cose.Generic_Headers, * cose.label => cose.values, } cose.Generic_Headers = ( ? 1 => int / tstr, ? 2 => [+ cose.label], ? 3 => tstr / int, ? 4 => bstr, ? (5 => bstr // 6 => bstr), ) cose.label = int / tstr cose.values = any¶
The import
statement can also request an alias for an imported name:¶
$ cddlc -2tcddl - mydata = {Fritz: cose.empty_or_serialized_map} ;# import empty_or_serialized_map from rfc9052 as cose¶
Note how an additional rule provides an alias for
empty_or_serialized_map
that does not have the namespace prefix:¶
mydata = {"Fritz" => cose.empty_or_serialized_map} empty_or_serialized_map = cose.empty_or_serialized_map cose.empty_or_serialized_map = bstr .cbor cose.header_map / bstr .size 0 cose.header_map = { cose.Generic_Headers, * cose.label => cose.values, } cose.Generic_Headers = ( ? 1 => int / tstr, ? 2 => [+ cose.label], ? 3 => tstr / int, ? 4 => bstr, ? (5 => bstr // 6 => bstr), ) cose.label = int / tstr cose.values = any¶
Tools may provide a convenient way to initiate the processing of directives from the command line.¶
A tool may provide a way to root the module tree from the command line:¶
$ cddlc -2tcddl -icose=rfc9052 -scose.COSE_Key¶
The command line argument -icose=rfc9052
is a shortcut for¶
;# import rfc9052 as cose¶
Together with the start rule name, cose.COSE_Key
, this results in the following CDDL 1.0 specification:¶
$.start.$ = cose.COSE_Key cose.COSE_Key = { 1 => tstr / int, ? 2 => bstr, ? 3 => tstr / int, ? 4 => [+ tstr / int], ? 5 => bstr, * cose.label => cose.values, } cose.label = int / tstr cose.values = any¶
In other words, the module synthesized from the command line had an
empty CDDL file, which therefore was not provided (no -
on the
command line).¶
The module structure specified in this document is not believed to create additional security considerations beyond the general security considerations in Section 5 of [RFC8610].¶
Implementations that employ the module structure defined in this document need to ascertain the provenance of the modules they combine into the CDDL models they employ operationally. This specification does not define how the source directories accessed via the CDDL_INCLUDE_PATH are populated; this process needs to undergo the same care and scrutiny as any other introduction of source code into a build environment.¶
This document has no IANA actions.¶
TO DO¶
directive = ";#" RS (%s"import" / %s"include") RS [from-clause] filename [as-clause] CRLF from-clause = 1*(id [","] RS) %s"from" RS as-clause = RS %s"as" RS id filename = 1*("-" / "." / %x30-39 / %x41-5a / "_" / %x61-7a) id = ("$" / %x40-5a / "_" / %x61-7a) *("$" / %x30-39 / %x40-5a / "_" / %x61-7a) RS = 1*WS WS = SP SP = %x20 CRLF = %x0A / %x0D.0A¶
This appendix is for information only.¶
A rough CDDL 2.0 tool is available [cddlc]. It can process CDDL 2.0 models into CDDL 1 models that can then be processed by the CDDL tool described in Appendix F of [RFC8610].¶
A typical command line involving both tools might be:¶
cddlc -2 -tcddl mytestfile.cddl | cddl - gp 10¶
Install on a system with a modern Ruby (Ruby version ≥ 3.0) via:¶
gem install cddlc¶
The present document assumes the use of cddlc
version 0.1.8.¶
TODO acknowledge.¶