fix(dtls): replace panicking unwrap/expect in crypto hot paths#68
Open
nightness wants to merge 1 commit intowebrtc-rs:masterfrom
Open
fix(dtls): replace panicking unwrap/expect in crypto hot paths#68nightness wants to merge 1 commit intowebrtc-rs:masterfrom
nightness wants to merge 1 commit intowebrtc-rs:masterfrom
Conversation
- generate_self_signed_with_alg: replace 3x .unwrap() with ? operator - Config::build(): replace .build().unwrap() on rustls verifier with ? - flight5::generate(): extract certificate ref with ok_or_else() instead of .unwrap(), returning a proper Fatal/InternalError DTLS alert - CryptoPrivateKey::Clone: add Safety comment explaining why re-parsing serialized_der is sound; upgrade bare .unwrap() to .expect() with descriptive message so panics are diagnosable if they ever occur Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fdf2918 to
c8122f9
Compare
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.
Summary
crypto/mod.rsgenerate_self_signed_with_alg: replaces 3×.unwrap()with?— function already returnsResult<Self>config.rsConfig::build(): replaces.build().unwrap()on the rustlsWebPkiServerVerifierbuilder with.map_err(|e| Error::Other(...))?— function already returnsResult<HandshakeConfig>flight/flight5.rsFlight5::generate(): extracts the certificate ref withok_or_else()returning a properFatal/InternalErrorDTLS alert instead of panicking with.unwrap()— function already returnsResult<_, (Option<Alert>, Option<Error>)>crypto/mod.rsCryptoPrivateKey::Clone: theClonetrait cannot returnResult; adds a// Safety:comment explaining why re-parsingserialized_deris sound, and upgrades bare.unwrap()to.expect()with descriptive messages so any unexpected panic is diagnosableWhy This Matters
Panics in DTLS crypto paths terminate the peer connection (and potentially the process) instead of propagating a negotiation error. The
flight5unwrap in particular can fire during an active handshake if the local certificate is unexpectedly absent.Test Plan
cargo build -p rtc-dtlspasses (verified)cargo test -p rtc-dtlspasses🤖 Generated with Claude Code