Skip to content

feat(webrtc-utils): add Fingerprint::from_sdp_format - #6571

Open
yexiyue wants to merge 2 commits into
libp2p:masterfrom
yexiyue:feat/fingerprint-from-sdp-format
Open

feat(webrtc-utils): add Fingerprint::from_sdp_format#6571
yexiyue wants to merge 2 commits into
libp2p:masterfrom
yexiyue:feat/fingerprint-from-sdp-format

Conversation

@yexiyue

@yexiyue yexiyue commented Jul 28, 2026

Copy link
Copy Markdown

Description

Fingerprint can be rendered into the RFC 4572 §5 SDP format via to_sdp_format, but
there is no way back. Anyone who needs to read a fingerprint out of an SDP has to hand-roll the
hex/colon decoding — an out-of-tree transport parsing localDescription, or a test asserting
against a rendered description.

This adds the inverse:

pub fn from_sdp_format(sdp: &str) -> Option<Self>

Colons are separators and hex is case-insensitive, so both are accepted on the way in
(AB:CD:…, abcd…, and every mix round-trip to the same fingerprint). Malformed input yields
None rather than a truncated fingerprint — a wrong fingerprint surfaces as a DTLS handshake that
fails much later, which is considerably harder to diagnose than a parse failure at the source.

The existing from_sdp test decoded the constant by hand with hex::decode and compared the
result to itself, so it exercised no library code at all. It now goes through the new method, and
three more tests cover the round trip, the accepted spellings, and the rejected ones.

AI Assistance Disclosure

Tools used (required — write none if no AI was used): Claude Code

Attestation (required):

  • I have read every line of this diff, understand what it does, and can explain it in review.

Notes & open questions

This came out of building a WebRTC-Direct transport outside the tree: the browser side has to read
the DTLS fingerprint back out of RTCPeerConnection.localDescription, so I ended up writing this
parser by hand. It seemed to belong next to to_sdp_format rather than in my crate.

hex is already a dependency of libp2p-webrtc-utils (used by Fingerprint's Debug impl), so
this adds nothing to the dependency tree.

The changelog entry has a placeholder PR number; happy to push the real one once this is assigned.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

yexiyue added 2 commits July 28, 2026 19:09
`Fingerprint` can be rendered into the RFC 4572 SDP format but not parsed back
out of it, so anyone reading a fingerprint off an SDP -- an out-of-tree
transport, or a test asserting against a rendered description -- has to hand-roll
the hex/colon decoding. Add the inverse of `to_sdp_format`.

Colons are separators and hex is case-insensitive, so both are accepted on the
way in. Malformed input yields `None` rather than a truncated fingerprint: a
wrong fingerprint surfaces as a DTLS handshake that fails much later, which is
considerably harder to diagnose.

The existing `from_sdp` test decoded the constant by hand and compared it to
itself, exercising no library code; it now goes through the new method.
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