From cbc8772d4ab749c70634b2f1c7e76e509e69f363 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 23 Sep 2026 09:53:34 +0800 Subject: [PATCH] stream: set_negotiated_key, one place that maps the picked version to a key Every handshake picked a version and then repeated the same choice: at least 1 splits the key, 0 sets it as before. Stream now makes that choice from the transcript it is already given, so callers make one call and a later version is handled here rather than at each of them. Version 0 still goes through set_key. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019aokqJuhjvB3kijXtAg5Ns --- src/stream.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/stream.rs b/src/stream.rs index 6260f39a5..6571520c3 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -80,15 +80,20 @@ impl Stream { } } - /// Per-direction keys bound to the handshake; see `tcp::KX_VERSION_LATEST`. `is_initiator` - /// is the side that sent the sealed key. + /// The stream key for the key exchange version in `t.picked`: version 0 is `set_key`, and + /// later versions derive one key per direction from the transcript. `is_initiator` is the + /// side that sent the sealed key. #[inline] - pub fn set_key_split( + pub fn set_negotiated_key( &mut self, key: Key, is_initiator: bool, t: &tcp::KxTranscript, ) -> ResultType<()> { + if t.picked == 0 { + self.set_key(key); + return Ok(()); + } match self { #[cfg(feature = "webrtc")] Stream::WebRTC(s) => {