Skip to content

refactor: change nonce parameter type from byte slice to u32 - #762

Merged
Benoît Cortier (CBenoit) merged 3 commits into
masterfrom
claude/clever-meitner-go9tyy
Oct 1, 2026
Merged

Benoît Cortier (CBenoit) merged 3 commits into
masterfrom
claude/clever-meitner-go9tyy

Conversation

@CBenoit

@CBenoit Benoît Cortier (CBenoit) commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #759, applying this review suggestion: keep the KDC-REQ nonce as a u32 all the way to the encoding boundary instead of round-tripping it through big-endian bytes at every call site.

Key Changes

  • GenerateAsReqOptions::nonce is now u32 instead of &'a [u8] (breaking change for external users of this public struct).
  • GenerateAsPaDataOptions::authenticator_nonce (PKINIT) is now u32 instead of [u8; 4].
  • nonce_to_asn1 now takes a u32 and remains the single place that encodes a nonce (signed minimal DER Int32), with the rationale documented there. It is used by generate_as_req_kdc_body, generate_tgs_req and the PKINIT PkAuthenticator.
  • Removed the .to_be_bytes() conversions at the call sites in the Kerberos client, change-password, server AS exchange and PKU2U.
  • Tests use u32 literals (e.g. 0x0009_a792) instead of byte arrays.

The encoded bytes are identical to before; this is a type/API refactor only.

Testing

  • cargo test --features network_client,dns_resolver,scard,__test-data passes.
  • cargo fmt and clippy (lib/bins/examples, -D warnings) are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01A55uC5v7JmckNf5r2X4t4g

Keep the nonce as a u32 from generation to the encoding boundary instead
of round-tripping it through big-endian bytes at every call site.
nonce_to_asn1 now takes the u32 directly, and the PKINIT
authenticator_nonce is a u32 as well.

BREAKING CHANGE: GenerateAsReqOptions::nonce is now a u32 instead of &[u8].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A55uC5v7JmckNf5r2X4t4g
Copilot AI balanced review requested due to automatic review settings September 30, 2026 17:27

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.

Copilot review overview

🟢 Approval recommended

The type migration is consistently applied and existing DER edge-case coverage confirms preserved encoding behavior.

Review effort: Balanced
Findings: None

What changed in this PR

Refactors Kerberos and PKU2U nonce handling to use u32 while preserving DER encoding behavior.

Changes:

  • Centralizes big-endian conversion in nonce_to_asn1.
  • Updates nonce option fields and call sites to use u32.
  • Migrates nonce-related tests to integer literals.
File Description
src/​pku2u/​mod.rs Passes generated nonces directly.
src/​pku2u/​extractors.rs Updates test nonce inputs.
src/​pk_init.rs Changes authenticator nonce to u32.
src/​kerberos/​server/​as_exchange.rs Removes call-site byte conversion.
src/​kerberos/​client/​mod.rs Passes generated nonces directly.
src/​kerberos/​client/​generators.rs Refactors nonce API, encoding, and tests.
src/​kerberos/​client/​change_password.rs Uses the generated u32 nonce directly.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

With the nonce carried as a u32, the DER conversion now happens inline
where each nonce is encoded, and the encoding rationale lives on the
GenerateAsReqOptions::nonce field. The helper's test cases move to the
AS-REQ body test so they exercise the real encoding path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A55uC5v7JmckNf5r2X4t4g
@CBenoit Benoît Cortier (CBenoit) changed the title Change nonce parameter type from byte slice to u32 refactor: change nonce parameter type from byte slice to u32 Sep 30, 2026

@jborean93 Jordan Borean (jborean93) 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.

Just a comment, feel free to ignore it but thought I would just ask.

Do you also need to bump the major version now that there is a breaking change or is the versioning done separately?

I can also verify that this does't regress my original problem so the changes are good logic wise there.

Comment thread src/kerberos/client/generators.rs
Keep the nonce DER encoding and its rationale in one helper so every
encoding site (AS-REQ, TGS-REQ, PKINIT) uses the same signed minimal
encoding instead of each repeating the conversion. The nonce stays a
u32 up to that boundary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A55uC5v7JmckNf5r2X4t4g
@CBenoit

Copy link
Copy Markdown
Member Author

Jordan Borean (@jborean93) Thank you for the review!

Do you also need to bump the major version now that there is a breaking change or is the versioning done separately?

Rust crate is indeed done via a separate PR through release-plz, with breaking change detection, and the NuGet package is automatically published with today’s date upon running the workflow 🙂

I can also verify that this does't regress my original problem so the changes are good logic wise there.

I would appreciate that! If you’re okay with that, I’ll publish the next version once you confirm everything is good for you?

@jborean93

Copy link
Copy Markdown
Contributor

I would appreciate that! If you’re okay with that, I’ll publish the next version once you confirm everything is good for you?

Would be great to get a new release but if it was me I would probably wait for #758 to be in before the next release. This has some unexpected consequences where credentials set by other threads could be shared unexpectedly.

Entirely up to you though, this is your project and I've worked around the problem #758 fixes by just using unique usernames in my test.

@CBenoit

Copy link
Copy Markdown
Member Author

Would be great to get a new release but if it was me I would probably wait for #758 to be in before the next release. This has some unexpected consequences where credentials set by other threads could be shared unexpectedly.

Agreed; in fact I already merged that other PR, so it will be part of the next release.

I’ll just wait for an approval on this one too, and then I think we’re good to go.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@CBenoit
Benoît Cortier (CBenoit) merged commit fa4efe5 into master Oct 1, 2026
68 checks passed
@CBenoit
Benoît Cortier (CBenoit) deleted the claude/clever-meitner-go9tyy branch October 1, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants