Skip to content

Make certificate encodings conditional.#93

Open
werwurm wants to merge 3 commits intomainfrom
werwurm/make_conditional_encodings
Open

Make certificate encodings conditional.#93
werwurm wants to merge 3 commits intomainfrom
werwurm/make_conditional_encodings

Conversation

@werwurm
Copy link
Copy Markdown
Contributor

@werwurm werwurm commented Mar 27, 2026

Libnat20 provides both x509 and COSE/CWT support in the main
functionality function n20_issue_certificate. This means that if a
project uses n20_issue_certificate all of the certificate rendering
code for x509 and COSE/CWT will be linked in and referenced even
if the project never actually uses one or the other. This leads
to a lot of dead code which cannot be optimized out by the linker.

This patch introduces preprocessor macros to allows for selectively
enabling and disabling either encoding for the purpose of building
libnat20 as concise as required by the intended use case.

Add CI configurations for encoding-only builds.

Extend cmake-build-and-test workflow to test all supported certificate
encoding configurations: both encodings, X509 only, and COSE only.

Changes:

  • Add x509-only configuration (NAT20_WITH_X509=ON, NAT20_WITH_COSE=OFF)
  • Add cose-only configuration (NAT20_WITH_X509=OFF, NAT20_WITH_COSE=ON)
  • Add descriptive job names showing configuration being tested
  • Matrix now runs 4 jobs: no-tests, both-encodings, x509-only, cose-only

This ensures conditional compilation works correctly and prevents
regressions when modifying encoding-specific code.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

LCOV of commit 39c8de5 during lcov-test-coverage-report #141

Summary coverage rate:
  lines......: 95.7% (3013 of 3147 lines)
  functions..: 99.1% (230 of 232 functions)
  branches...: 87.2% (1646 of 1887 branches)

Files changed coverage rate: n/a

@werwurm werwurm force-pushed the werwurm/make_conditional_encodings branch from db7c88a to c128991 Compare March 27, 2026 17:35
@werwurm werwurm requested a review from Copilot March 27, 2026 17:37
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces build-time feature flags to selectively compile X.509 and/or COSE/CWT certificate encoding support, reducing unnecessary linked code when projects only use one encoding. It also expands CI to validate the supported encoding configurations.

Changes:

  • Add NAT20_WITH_X509 / NAT20_WITH_COSE CMake options and compile-time defines (N20_WITH_X509, N20_WITH_COSE).
  • Conditionally compile X.509/COSE-dependent code paths in core functionality and tests.
  • Extend the GitHub Actions CMake workflow matrix to test both encodings, x509-only, and cose-only configurations.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/service/test/gnostic.cpp Wrap X.509-specific service tests with #ifdef N20_WITH_X509.
src/core/test/functionality.cpp Guard X.509 and COSE test sections behind N20_WITH_X509 / N20_WITH_COSE.
src/core/functionality.c Add conditional compilation blocks for X.509 and COSE implementation/dispatch.
CMakeLists.txt Introduce encoding options and define N20_WITH_X509 / N20_WITH_COSE.
.github/workflows/cmake-build-and-test.yml Add CI matrix jobs for both-encodings, x509-only, and cose-only.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

werwurm added 2 commits March 27, 2026 13:30
Libnat20 provides both x509 and COSE/CWT support in the main
functionality function n20_issue_certificate. This means that if a
project uses n20_issue_certificate all of the certificate rendering
code for x509 and COSE/CWT will be linked in and referenced even
if the project never actually uses one or the other. This leads
to a lot of dead code which cannot be optimized out by the linker.

This patch introduces preprocessor macros to allows for selectively
enabling and disabling either encoding for the purpose of building
libnat20 as concise as required by the intended use case.

Add CI configurations for encoding-only builds.

Extend cmake-build-and-test workflow to test all supported certificate
encoding configurations: both encodings, X509 only, and COSE only.

Changes:
- Add x509-only configuration (NAT20_WITH_X509=ON, NAT20_WITH_COSE=OFF)
- Add cose-only configuration (NAT20_WITH_X509=OFF, NAT20_WITH_COSE=ON)
- Add descriptive job names showing configuration being tested
- Matrix now runs 4 jobs: no-tests, both-encodings, x509-only, cose-only

This ensures conditional compilation works correctly and prevents
regressions when modifying encoding-specific code.
@werwurm werwurm force-pushed the werwurm/make_conditional_encodings branch from fd7c8d7 to e570a00 Compare March 27, 2026 20:30
@werwurm werwurm changed the base branch from werwurm/tidy_path_length to main March 27, 2026 20:31
@werwurm werwurm marked this pull request as ready for review March 27, 2026 20:32
@werwurm werwurm requested a review from a team as a code owner March 27, 2026 20:32
@werwurm werwurm requested review from mjain02 and seidelrj March 27, 2026 20:32
…rent build systems don't have to add macro definitions to keep the behavior consistent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants