feat(webrtc-utils): add Fingerprint::from_sdp_format - #6571
Open
yexiyue wants to merge 2 commits into
Open
Conversation
`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.
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.
Description
Fingerprintcan be rendered into the RFC 4572 §5 SDP format viato_sdp_format, butthere 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 assertingagainst a rendered description.
This adds the inverse:
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 yieldsNonerather than a truncated fingerprint — a wrong fingerprint surfaces as a DTLS handshake thatfails much later, which is considerably harder to diagnose than a parse failure at the source.
The existing
from_sdptest decoded the constant by hand withhex::decodeand compared theresult 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
noneif no AI was used): Claude CodeAttestation (required):
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 thisparser by hand. It seemed to belong next to
to_sdp_formatrather than in my crate.hexis already a dependency oflibp2p-webrtc-utils(used byFingerprint'sDebugimpl), sothis 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