Repository navigation
perf(xmldsig): sign without reparsing each step - #305
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 10 minutes. View limit details
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Document-aware output and KeyInfo merging src/document.rs, src/operation.rs, src/xmldsig/mutation.rs, src/xmldsig/sign.rs |
Added bounded text projection and document batch/projection execution paths. KeyInfo merging accepts a parsed document, and signing selects document commit or text projection output. |
Deferred digest calculation and SignedInfo canonicalization src/c14n/mod.rs, src/xmldsig/parse.rs, src/xmldsig/sign.rs, src/xmldsig/sign/deferred_commit_tests.rs, src/xmldsig/sign/error_conversion_tests.rs, tests/signing_digest.rs |
Eligible single-level plans compute pending digest values without an intermediate document transition. SignedInfo parsing and canonicalization use those values. Tests cover output equivalence, canonical SignedInfo, node limits, and updated XPath budget counts. |
Priority:
Estimated code review effort: 4 (Complex) | ~55 minutes
Change: Refactor · Severity of issue fixed: Medium
Sequence Diagram(s)
sequenceDiagram
participant ReferenceFilling
participant SignedInfoParser
participant SignedInfoCanonicalizer
participant SigningKey
participant SignedOutput
ReferenceFilling->>SignedInfoParser: pending DigestValue identities and values
SignedInfoParser->>SignedInfoCanonicalizer: parsed SignedInfo with pending values
SignedInfoCanonicalizer->>SigningKey: canonical SignedInfo bytes
SigningKey->>SignedOutput: signature value
SignedOutput->>SignedOutput: commit document or project text output
Merge Risk: 
Minimal · up to d235f
-
This change speeds up XML signing by avoiding repeated document parses. The supplied evidence shows no concrete defect in the output or in the refusal behavior. The PR states that output is byte-identical and the tests cover the deferred path, so merge risk is minimal.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Directly linked issue
#304has four coding objectives. (1) KeyInfo merge reads the current parsed view and drops its validation parse. The summary of src/xmldsig/mutation.rs and src/xmldsig/sign.rs confirms this. (2) String entry points (sign_template, sign_with_builder) serialize the final generation without a reparse. Retained-document entry points still commit a validated generation. The summary of src/xmldsig/sign.rs confirms this. (3) Dependency analysis uses the current tree for enveloped-signature, XPath exclude-signatures and canonicalization transform chains. Other chains keep placeholder analysis, as#304allows. (4) With one dependency level and empty DigestValues, digests fill the canonical SignedInfo through src/xmldsig/parse.rs and sign.rs. No intermediate reparse occurs. Acceptance evidence: src/xmldsig/sign/deferred_commit_tests.rs (read at head) compares text output with committed-document output for exclusive, inclusive, XPath, nested-Manifest and pre-filled templates. It checks the canonical SignedInfo passed to the key against an independent canonicalization. It checks node-limit parity between projection and commit parse. The PR reports byte-identical output on measured sizes, a 414 ms to 108–112 ms timing, a full test run of 5641 passed, and refusal behavior unchanged. The eight-to-two parse count is supported by the code summary and the adjusted budget tests (tests/signing_digest.rs and src/xmldsig/sign/error_conversion_tests.rs). It is not measured directly by a parse counter in the diff. I did not rerun the reported timings or the test suite.
Full details: Out of Scope Changes check
-
Explanation
The changed files support the fast paths in
#304. src/c14n/mod.rs adds a crate-private bounded canonicalization entry point that returns tracked start-tag positions for deferred digest insertion. src/document.rs adds project_base64_commit, which projects the node count and output without parsing. This serves the node-limit parity requirement. src/operation.rs adds run_document_batch_with_budgets and run_document_projection. The PR reports clippy with -D warnings passing, so these methods are used and are not dead code. src/xmldsig/parse.rs adds a SignedInfo parse path that accepts pending DigestValue text. The existing parsers delegate with an empty list, so their behavior is unchanged. src/xmldsig/mutation.rs separates standalone and in-document KeyInfo merging. Test updates in src/xmldsig/sign/error_conversion_tests.rs and tests/signing_digest.rs change XPath expression budget counts. The PR discloses this as a consequence of one fewer XPath parse on the single-level path. Changes are gated to xmldsig where the summaries state so. No change was found that is unrelated to#304.
-
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment @coderabbitai help to get the list of available commands.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d235f07dbc
ℹ️ 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".
Signing a template parsed the whole document eight times; on a 1.7 MB SAML response the parses took about 92% of the operation. Signing now parses the input and the KeyInfo commit only: - Merge KeyInfo sources against the current parsed view and rely on the commit parse for validation instead of a separate validation parse. - Derive the Reference dependency plan from the current tree when every transform is enveloped-signature, XPath exclusion of signatures or canonicalization: these keep or drop whole subtrees, so a mutable DigestValue or SignatureValue is covered exactly when its future text is. Other chains keep the placeholder analysis. - When no Reference depends on another digest and every DigestValue is empty, compute the digests from the current generation and splice them into the canonical SignedInfo at the end tag of each DigestValue, instead of committing an intermediate generation. - String entry points serialize the final generation directly, checking the projected size and node count the commit parse would enforce. Retained-document entry points still commit a validated generation. The output mode is a type parameter, so no path unwraps an option. Output is byte-identical to the previous implementation. XPath expressions in a single-level template are parsed once less, so the operation consumes less of the shared expression budget; the budget tests use the new count. 1.69 MB enveloped SAML response with X509 KeyInfo: 414 ms -> 108 ms. Closes #304
- Dependency analysis on the current tree assumed that filling a value removes only text. A SignatureValue or DigestValue holding elements loses them when filled, so a Reference to such an element was signed although the emitted document no longer contains it. The current tree is now used only when every value holds text alone; otherwise the placeholder analysis reports the missing target as before. - Admitting deferred digests assumed each replacement grows the document. A DigestValue of references to an empty entity has no semantic children but more source bytes than its digest, and the subtraction overflowed. The total now adds each projected length and subtracts the unchanged base. Regression tests: signing_refuses_a_reference_to_content_the_signature_value_replaces and deferred_digest_may_replace_longer_lexical_content.
2d39128 to
9da0fc0
Compare
Summary
Template signing parsed the whole document eight times. It now parses twice: once for the input and once for the KeyInfo commit.
DigestValueorSignatureValueis covered exactly when its future text is. This holds only while every value holds text alone; a value with element content, and every other transform chain, keeps the placeholder analysis.DigestValueis empty, the digests are computed from the current generation. They are inserted into the canonicalSignedInfoat eachDigestValueend tag, instead of being committed to an intermediate generation. C14N writes an empty element as a start/end pair and escapes<in attribute values. Base64 needs no escaping (C14N 1.0 §5.2), so the result is the canonical form of the filled element.sign_template,sign_with_builder) serialize the final generation directly. They check the projected size and node count that the commit parse would have enforced.Option.Performance
1.69 MB enveloped SAML response, 16384 attributes, RSA-SHA256, exclusive C14N, X509 KeyInfo writer (macOS, release, median of 15, both runs back to back in one session):
On every measured size the output is byte-identical to the previous implementation.
Behaviour notes
SignedInfoparse and builder validation charge the same allowance.Testing
cargo fmt --check.cargo clippy --workspace --all-targets --all-features -D warningson stable.check-features.shlint for the dsig, xmlenc and c14n profiles on 1.92.cargo nextest run --workspace --all-featureswith the xmlsec1 oracle and SoftHSM: 5641 passed.cargo doc -D warningsandcargo test --doc.src/xmldsig/sign/deferred_commit_tests.rs:SignedInfohanded to the key equals an independent canonicalization of the emitted document;SignatureValueis refused;DigestValueof references to an empty entity (roxmltree, internal DTD), whose replacement shrinks the document, signs.Closes #304