Skip to content

feat(xmlenc): add encryption pipeline#96

Merged
polaz merged 17 commits into
mainfrom
feat/#95-xmlenc-encrypt
Jul 21, 2026
Merged

feat(xmlenc): add encryption pipeline#96
polaz merged 17 commits into
mainfrom
feat/#95-xmlenc-encrypt

Conversation

@polaz

@polaz polaz commented Jul 21, 2026

Copy link
Copy Markdown
Member

Summary

  • add a complete pure-Rust XMLEnc encryption pipeline for binary data, XML elements, and XML content
  • support AES-128/256-CBC, AES-128/256-GCM, RSA-OAEP 1.0/1.1, AES-128/256 Key Wrap, and multiple recipients
  • add bounded document replacement, donor fixtures, SAML coverage, documentation, and a runnable example

Security

  • use the operating-system RNG for content keys, IVs, nonces, and RSA-OAEP
  • reject malformed XML, incompatible key sources, invalid key sizes, excessive inputs and recipients, and unsupported legacy configurations
  • keep external resource retrieval and C/C++ FFI outside the runtime path

Testing

  • cargo nextest run --all-features --no-fail-fast (618 passed, 0 skipped)
  • cargo test --doc --all-features (4 passed)
  • cargo check --all-features
  • cargo check --no-default-features --features xmlenc
  • cargo check --examples
  • cargo check --examples --features xmlenc
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo package --allow-dirty
  • external decryption interoperability with xmlsec1 1.3.12

Closes #95

- implement AES-CBC/GCM encryption and recipient key wrapping
- add document replacement, bounds, interoperability tests, and docs
- import donor encryption templates without normalizing their bytes

Closes #95
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 826c9ee5-6372-4a20-b802-5226cf2c29ce

📥 Commits

Reviewing files that changed from the base of the PR and between a985531 and 1eba243.

📒 Files selected for processing (1)
  • src/xmlenc/mod.rs

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added end-to-end XML Encryption builder for AES-CBC/GCM, with RSA-OAEP and AES Key Wrap recipients (including multiple recipients).
    • Supports encrypting full XML elements, element content, or targeting selected document nodes.
    • Added a new runnable encryption example.
  • Documentation
    • Expanded README to document encrypt/decrypt pipelines, supported profiles, bounds, and interoperability details.
  • Bug Fixes
    • Improved decryption diagnostics, including redacted debug output and stricter plaintext/target validation.
  • Tests
    • Added/expanded xmlenc integration and xmlsec1 interoperability test coverage; updated fixture corpus.

Walkthrough

XMLEnc encryption support is added for AES-CBC/GCM content, RSA-OAEP and AES-KW recipients, XML element/content replacement, structured validation errors, donor fixtures, integration tests, and xmlsec1 interoperability.

Changes

XMLEnc encryption pipeline

Layer / File(s) Summary
Public encryption contracts
src/xmlenc/types.rs, src/xmlenc/mod.rs, README.md, Cargo.toml, src/lib.rs, examples/encrypt.rs
Adds public encryption types, bounds, errors, exports, documentation, feature wiring, and a runnable encryption example.
Encryption and XML replacement
src/xmlenc/encrypt.rs
Implements AES-CBC/GCM encryption, RSA-OAEP and AES-KW wrapping, XML rendering, document targeting, element/content replacement, validation, and unit coverage.
Decryption compatibility and key redaction
src/xmlenc/decrypt.rs
Updates RSA-OAEP RNG error handling and redacts symmetric keys and KEKs from debug output.
Donor fixtures and regression coverage
tests/xmlenc_encrypt_integration.rs, tests/fixtures/xmlenc/..., scripts/import-donor-fixtures.sh, tests/fixtures_smoke.rs, .gitattributes
Adds donor templates and coverage for algorithms, recipients, replacement modes, SAML content, validation, tampering, and metadata.
xmlsec1 interoperability
tests/xmlenc_encrypt_xmlsec1.rs
Adds version-gated interoperability tests for direct AES-GCM and RSA-OAEP-wrapped AES-CBC output.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant EncryptedDataBuilder
  participant AES
  participant KeyWrapper
  participant xmlsec1
  Caller->>EncryptedDataBuilder: configure and encrypt XML
  EncryptedDataBuilder->>AES: encrypt plaintext
  EncryptedDataBuilder->>KeyWrapper: wrap content key for recipients
  KeyWrapper-->>EncryptedDataBuilder: return encrypted keys
  EncryptedDataBuilder-->>Caller: return EncryptedData XML
  Caller->>xmlsec1: decrypt generated XML
  xmlsec1-->>Caller: return plaintext
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the new XMLEnc encryption pipeline.
Description check ✅ Passed The description is detailed and directly matches the encryption-focused changeset.
Linked Issues check ✅ Passed The changes cover the requested XMLEnc encryption APIs, recipient support, bounds, tests, docs, and xmlsec1 interoperability.
Out of Scope Changes check ✅ Passed No clear out-of-scope code changes stand out; the fixture, example, docs, and test updates all support the encryption work.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/#95-xmlenc-encrypt

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a pure-Rust XMLEnc encryption pipeline. The main changes are:

  • AES-128/256-CBC and AES-128/256-GCM encryption.
  • RSA-OAEP and AES Key Wrap recipient support.
  • Multiple recipients and direct content keys.
  • XML element and content replacement with input limits.
  • Integration fixtures, interoperability tests, documentation, and an example.

Confidence Score: 5/5

This looks safe to merge.

The element-content boundary uses the selected element's bounded source range. RSA-OAEP randomness failures are returned through typed errors. No blocking issues were found in the changed code.

T-Rex T-Rex Logs

What T-Rex did

  • The test run for the pull request was executed and completed with an exit code of 0.
  • The results show 11 passed, 0 failed, and 0 ignored tests.
  • The captured log was reviewed and confirms the command, working directory, exit code, test names, and the Cargo summary were recorded.
  • A log artifact of the test run was uploaded and linked for reviewers.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/xmlenc/encrypt.rs Adds content encryption, key wrapping, XML serialization, target selection, and bounded document replacement.
src/xmlenc/decrypt.rs Updates RSA-OAEP error handling, shares element validation, and redacts symmetric keys from debug output.
src/xmlenc/types.rs Adds encryption configuration, recipient, result, limit, and error types.
src/xmlenc/mod.rs Exports the encryption API and adds shared XML element validation.
tests/xmlenc_encrypt_integration.rs Adds integration coverage for encryption, document replacement, SAML inputs, and invalid configurations.

Reviews (5): Last reviewed commit: "refactor(xmlenc): clarify element valida..." | Re-trigger Greptile

Comment thread src/xmlenc/encrypt.rs
Comment thread src/xmlenc/encrypt.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9d712aa95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread examples/encrypt.rs
Comment thread src/xmlenc/encrypt.rs
Comment thread src/xmlenc/encrypt.rs
polaz added 7 commits July 21, 2026 14:06
Document why the selected node range makes the final closing marker unambiguous and lock the behavior with a round-trip regression test.
Document that direct PaddingScheme dispatch preserves SysRng failures as typed RSA errors rather than using the infallible convenience API.
Require the xmlenc feature before Cargo builds the encryption example so default example checks remain valid.
Require oversized XML input to fail at the size boundary before malformed content reaches the parser.
Reject oversized standalone XML before parser work or Content wrapper allocation.
Require encryption to reject empty direct and recipient key names before emitting XML rejected by the reciprocal parser.
Keep generated encryption XML compatible with the reciprocal parser by validating direct and recipient KeyName values.
@polaz

polaz commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b6f59dd467

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/xmlenc/encrypt.rs
Comment thread src/xmlenc/encrypt.rs Outdated
Comment thread src/xmlenc/encrypt.rs
polaz added 7 commits July 21, 2026 14:48
Add a regression test and typed limit contract proving document encryption must reject oversized XML before parsing it.
Reject oversized caller XML before invoking roxmltree while retaining the existing plaintext-size check for the selected node.
Prove Element plaintext accepts boundary whitespace and comments while rejecting processing instructions that document replacement cannot consume.
Share the reciprocal Element node-set contract so encryption and document decryption both allow boundary whitespace/comments and reject processing instructions.
Cover XML-forbidden characters across EncryptedData Id, recipient identifiers, and direct/wrapped KeyName values.
Reject code points outside the XML 1.0 Char production before serializing caller-controlled attributes or KeyName text.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/xmlenc/mod.rs`:
- Around line 34-54: Refactor has_single_element_with_boundary_trivia to iterate
over parent.children() with a for loop instead of mutating element_count inside
Iterator::all. Count element nodes, immediately return false when more than one
is found, and return false for invalid non-comment/non-boundary-whitespace nodes
while preserving the final true result for exactly one valid element.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f3f08cda-1d29-40c4-8dd4-6434a436f71c

📥 Commits

Reviewing files that changed from the base of the PR and between a9d712a and a985531.

📒 Files selected for processing (6)
  • Cargo.toml
  • src/xmlenc/decrypt.rs
  • src/xmlenc/encrypt.rs
  • src/xmlenc/mod.rs
  • src/xmlenc/types.rs
  • tests/xmlenc_encrypt_integration.rs

Comment thread src/xmlenc/mod.rs
Use an explicit child-node loop so invalid siblings and a second element return immediately without closure state mutation.
@polaz

polaz commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 1eba243046

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@polaz
polaz merged commit f8ca8e5 into main Jul 21, 2026
10 checks passed
@polaz
polaz deleted the feat/#95-xmlenc-encrypt branch July 21, 2026 13:45
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.

Add complete XMLEnc encryption pipeline

1 participant