pub fn generate_cert(from_file: &str, tmpl: &Template) -> Result<Codegen>
Expand description

Generate the certificate template header and source file.

The generated files will indicate that they have been automatically generated from from_file. Returns the implementation first and the header file second. NOTE: the implementation file will #include "<header>.h" the header where <header> comes from tmpl.name.

The generated header file contains the following elements. Below <name> refers to tmpl.name and <Name> to the “camel-case” variant of <name>.

  1. License header, warning, include guard.
  2. Relevant includes.
  3. Definition of a data structure to hold the values of the variables used in the TBS. It is named <name>_tbs_values_t.
  4. Definition of a data structure to hold the values of the variables used in the signature. It is named <name>_sig_values_t. Note that this structure contains an extra field called tbs (and its size tbs_size) that must point to the buffer containing the TBS.
  5. An enumeration hold two values: one gives the maximum size of the TBS given the variables sizes defined in the template, and another one for the maximum size of the whole certificate. They are named k<Name>MaxTbsSizeBytes and k<Name>MaxCertSizeBytes respectively.
  6. Definition and documentation of a function that takes as input a a <name>_tbs_values_t and a buffer to produce the TBS. It is named <name>_build_tbs and returns a rom_error_t.
  7. Definition and documentation of a function that takes as input a a <name>_sig_values_t and a buffer to produce the certificate. It is named <name>_build_cert and returns a rom_error_t.