Skip to content

Audit public API to take arguments by reference where possible - #28

Closed
DanGould wants to merge 4 commits into
masterfrom
fix/402-ref-audit
Closed

DanGould wants to merge 4 commits into
masterfrom
fix/402-ref-audit

Conversation

@DanGould

@DanGould DanGould commented Mar 2, 2026

Copy link
Copy Markdown
Owner

Summary

Audit the public API to take arguments by reference where possible, following C-CALLER-CONTROL from the Rust API guidelines. Functions that previously took &T but internally cloned are changed to take T by value, letting the caller decide whether to clone or move.

Closes payjoin#402

Approach

Swept all pub fn signatures across payjoin, payjoin-cli, and payjoin-test-utils. Four commits cover HPKE, fetch_ohttp_keys, send::v2, and typestate documentation. Functions where ownership is intentional (persistence, crypto consumption) are documented rather than changed.

Open questions

None.

Pull Request Checklist
  • I have disclosed my use of AI in the body of this PR.
  • I have read CONTRIBUTING.md and rebased my branch to produce hygienic commits.

Disclosure: co-authored by Claude

DanGould added 4 commits March 1, 2026 14:53
Change encrypt_message_a, decrypt_message_a, encrypt_message_b,
and decrypt_message_b to borrow arguments they do not consume.

- encrypt_message_a: body Vec<u8> -> &[u8]
- decrypt_message_a: receiver_sk HpkeSecretKey -> &HpkeSecretKey
- encrypt_message_b: plaintext Vec<u8> -> &[u8]
- decrypt_message_b: sender_sk HpkeSecretKey -> &HpkeSecretKey

decrypt_message_b keeps receiver_pk owned because
OpModeR::Auth consumes the inner key.

Removes unnecessary .clone() calls at all call sites in
send/v2 and receive/v2.
The cert_der parameter is only passed to
Certificate::from_der which borrows it, so accept &[u8]
instead of Vec<u8>. Fix call sites in payjoin-cli and
payjoin-test-utils accordingly.

Other pub fns in io.rs and ohttp.rs keep ownership where
consumed (ohttp_context, impl IntoUrl).
Since encrypt_message_a now borrows its body argument,
extract_request no longer needs to own the Vec<u8>.
Change body parameter from Vec<u8> to &[u8].

Other pub fns in send/ keep ownership where consumed
(builder/typestate patterns, PsbtContextBuilder storage).
@coderabbitai

coderabbitai Bot commented Mar 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/402-ref-audit

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

@DanGould DanGould closed this Mar 2, 2026
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.

Audit public API to take arguments by reference where possible before v1.0 release

1 participant