Skip to content

host: give the hexadecimal text of identities one parser and one writer - #1688

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-1685-hex-identity-text
Nov 17, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-1685-hex-identity-text

Conversation

@ppenna

@ppenna Pedro Henrique Penna (ppenna) commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1685

What does this pull request change?

nvx::host now parses and writes the hexadecimal text of its identities with one function each, both private to the crate, in host::platform. Start with nvx/src/host/platform/mod.rs.

  • Before: platform::parse_hex_id, which parsed 32 digits into 16 bytes, and platform::parse_hex32, which parsed 64 digits into 32 bytes, had the same body apart from the length. The lowercase-hexadecimal Display loop was written three times: as snapshot::key's private write_hex, which KeyIdentity calls through the identity! macro, and inline in BootId and CaptureIdentity.
  • After: platform::parse_hex::<N> replaces both parsers, for 2 * N digits into [u8; N], and each caller infers N from the array that it builds: BootId, the host's and the boot's IDs, CaptureIdentity, and KeyIdentity. platform::write_hex, moved from snapshot::key, writes the text of BootId, CaptureIdentity, and KeyIdentity.
  • Unchanged: the text that each identity writes and parses, its error messages and ErrorKinds, its serde form, the public API, and every existing test.

A new unit test, host::platform::tests::hexadecimal_text_is_written_in_lowercase_and_read_in_either_case, covers both functions: a round trip in either case, the refusal of an odd, short, or long length, a digit beyond f, a sign, and a non-ASCII byte, and the lengths of the host's identities.

Left out: the follow-ups that #1685 lists: the host's other hexadecimal text, which builds a String byte by byte, as host::cli::hex does, and the same text outside host, in guest_restore, protocol, uuid, and the guest, which a crate-wide module could serve.

Why is this change needed?

Two parsers that differed only in a constant and three copies of one loop defined a single text form, so a change to that text had to be made in each copy, and each new identity added one. host::platform already held the parsers, and it lies beneath process, config, and snapshot in host's order of dependencies, which nvx/tests/host_modules.rs checks. All three already imported its parsers, so sharing the writer there adds no dependency between host's modules.

Alternatives rejected:

How was this change validated?

Checks and results, with Rust 1.97.1, at the base 621f8b2 and with the change, 842e7f5. The change preserves behavior, so the affected tests, unchanged, stand in for a reproduction:

Check Host Base 621f8b2 With the change
cargo test --locked --all-features --lib -- host::platform:: host::process:: host::config:: host::snapshot::key:: (in nvx/) Windows, local 124 passed, 0 failed, 3 ignored 125 passed, 0 failed, 3 ignored
The same Linux 107 passed, 0 failed, 2 ignored 108 passed, 0 failed, 2 ignored
python scripts\local_gates.py --base origin/dev --run, after cargo build --release --locked --features cli --manifest-path nvx/Cargo.toml Windows, local not run All 9 passed: test-changes (0 changed tests, 1 added), markdown-links, test-layout, nvx-format, nvx-lint, nvx-test (1099 library tests with all features), nvx-doc, nvx-msrv, and nvx-cli (2261 tests, 88 skipped, and 84 adversarial tests, 11 skipped)
python3 scripts/local_gates.py --base origin/dev --run --keep-going --only nvx-format nvx-lint nvx-test nvx-doc nvx-public-api nvx-msrv nvx-macos nvx-guest-binaries-lint nvx-guest-binaries-build Linux not run All 9 passed, among them nvx-public-api, nvx-macos, and both guest-binary gates; nvx-test ran 1816 library tests with all features

On both hosts, the tests that pin the identities' text, host_identities_are_read_as_openvmm_reads_them, boot_identities_have_one_text_form, the_current_boot_has_one_identity, equal_captures_have_one_identity_in_one_text, and identities_have_a_text_form, pass before and after the change.

A code-review pass over the whole diff found no issues.

Backend, host OS, host type, and guest: no VM ran. The Linux checks ran in a temporary worktree on an Azure Linux 3.0 virtual machine with KVM; the change starts no VM and affects no backend, so no microVM scenario applies.

Left to CI:

  • The Linux nvx-cli validation: the Linux host's Python lacks pip, which the gate's first step runs. Its Windows counterpart passed locally.
  • Every other job that CI selects.

CI run 44019934502 of the head, 842e7f5, passed, among its jobs nvx on Ubuntu and Windows, NVX CLI on Linux and Windows, and the microVM tests on KVM, MSHV, and WHP.

Checklist

  • Tests cover the new or fixed behavior, in the layout that
    python3 scripts/check_test_layout.py checks.
  • python3 scripts/check_test_changes.py --base origin/dev lists no change
    to an existing test, or a Changes to existing tests section below
    explains each one.
  • The documentation that the change affects is updated, including
    .github/copilot-instructions.md and the skills when a convention or
    workflow changes.
  • A change to the public API of nvx updates nvx-rs/public-api/ with
    python3 scripts/public_api.py --update.
  • Snapshots, protocols, and on-disk formats stay compatible, or the
    description says how the change versions or migrates them.

No documentation describes the functions that change, which are private to the crate. The public API, snapshots, protocols, and on-disk formats are unchanged: each identity writes and parses the same text, with the same messages, and python3 scripts/public_api.py passes.

host::platform held two parsers of hexadecimal identities that differed
only in their length: parse_hex_id, for 32 digits and 16 bytes, and
parse_hex32, for 64 digits and 32 bytes. The lowercase-hexadecimal
Display loop was written out three times: as snapshot::key's private
write_hex, which KeyIdentity's Display called through the identity!
macro, and inline in the Display of BootId and of CaptureIdentity.

host::platform now holds one const-generic parse_hex::<N>, the body of
both parsers for 2 * N digits, with which BootId, the host's and the
boot's IDs, CaptureIdentity, and KeyIdentity parse, each call inferring
N from the array that it builds; and one write_hex, moved from
snapshot::key, which the Display of all three identities calls.
host::platform already lies beneath process, config, and snapshot in
host's order of dependencies, and all three imported its parsers, so no
module depends on one that it did not depend on before. The text that
each identity writes and parses, its error messages, and its serde form
do not change.

The affected unit tests, those of host::platform, host::process,
host::config, and host::snapshot::key, pass unchanged at 621f8b2
and with the change, on Windows with Rust 1.97.1: 124 before, and 125
with the new test,
hexadecimal_text_is_written_in_lowercase_and_read_in_either_case,
which covers both functions: a round trip in either case, the refusal
of an odd, short, or long length, a digit beyond f, a sign, and a
non-ASCII byte, and the lengths of the host's identities.

Refs #1685

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 04:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the shared hexadecimal identity parsing and formatting changes.

No open issues 🎉

What changed in this PR

This PR addresses #1685 by centralizing hexadecimal identity parsing and formatting in nvx::host::platform, preserving existing text formats, errors, serialization, and public APIs.

Changes:

  • Replace the two fixed-length parsers with one const-generic parse_hex::<N>.
  • Share one lowercase hexadecimal writer across boot, capture, and snapshot key identities.
  • Add unit coverage for formatting, case-insensitive parsing, invalid input, and identity lengths without modifying existing tests.
File Description
nvx/​src/​host/​snapshot/​key.rs Use shared helpers and remove the local writer.
nvx/​src/​host/​process.rs Route BootId parsing and formatting through shared helpers.
nvx/​src/​host/​platform/​tests.rs Add hexadecimal parser and writer coverage.
nvx/​src/​host/​platform/​mod.rs Define the generic parser and shared writer; update host-ID parsing.
nvx/​src/​host/​platform/​linux/​process.rs Use the generic parser for Linux boot IDs.
nvx/​src/​host/​config/​mod.rs Use shared helpers for capture identity formatting and deserialization.

Review effort: Balanced

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.

host: give the hexadecimal text of identities one parser and one writer

2 participants