feat(rpc/ndr): add NDR encoder mirroring the decoder - #42
Open
hstern wants to merge 2 commits into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.