Skip to content

feat(rpc/ndr): add NDR encoder mirroring the decoder - #42

Open
hstern wants to merge 2 commits into
go-krb5:masterfrom
hstern:ndr-encoder
Open

feat(rpc/ndr): add NDR encoder mirroring the decoder#42
hstern wants to merge 2 commits into
go-krb5:masterfrom
hstern:ndr-encoder

Conversation

@hstern

@hstern hstern commented Jun 23, 2026

Copy link
Copy Markdown

Adds an NDR encoder (Encoder/NewEncoder/Encode + Marshal) — the inverse of the existing decoder, honoring the same ndr struct tags, alignment, conformant-array hoisting, deferred pointers, and Type-Serialization-v1 headers. Verified by round-tripping every decoder test vector (decode -> encode -> identical bytes) plus encode->decode->DeepEqual. Needed to marshal an MS-PAC (KERB_VALIDATION_INFO) downstream in go-krb5/krb5.

hstern and others added 2 commits June 22, 2026 11:48
Add Encoder/NewEncoder/Encode (and Marshal helper) producing DCE/RPC NDR
Type-Serialization-v1 output, the inverse of the existing Decoder: same
ndr struct tags, alignment, conformant-array hoisting, deferred pointers,
and common/private headers. Verified by round-tripping the decoder's own
test vectors (decode -> encode -> identical bytes).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Henry Stern <henry@stern.ca>
A pointer-tagged field equal to its type's zero value is a NULL NDR pointer
and must emit a zero referent id, round-tripping back to the zero value. The
encoder previously emitted a present referent for any non-Go-pointer kind, so
a nil pointer slice became a present empty array and a zero-value value type
(e.g. an absent RPC_SID embedded by pointer) became a present, populated
struct. Both broke decode -> encode -> decode and would corrupt a marshalled
MS-PAC's absent fields such as ExtraSIDs or ResourceGroupDomainSID.

Use reflect.Value.IsZero, which mirrors the decoder's representation of a NULL
pointer (the field is left at its zero value), so encoding the zero value as
NULL round-trips. A present, fully-zero value type is invalid in practice
(an RPC_SID has Revision 1) and is indistinguishable from NULL to the decoder.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Henry Stern <henry@stern.ca>
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.

1 participant