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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019aokqJuhjvB3kijXtAg5Ns
This commit is contained in:
rustdesk
2026-09-23 09:53:34 +08:00
co-authored by Claude Opus 5.5
parent 26582e163d
commit cbc8772d4a
+8 -3
View File
@@ -80,15 +80,20 @@ impl Stream {
} }
} }
/// Per-direction keys bound to the handshake; see `tcp::KX_VERSION_LATEST`. `is_initiator` /// The stream key for the key exchange version in `t.picked`: version 0 is `set_key`, and
/// is the side that sent the sealed key. /// later versions derive one key per direction from the transcript. `is_initiator` is the
/// side that sent the sealed key.
#[inline] #[inline]
pub fn set_key_split( pub fn set_negotiated_key(
&mut self, &mut self,
key: Key, key: Key,
is_initiator: bool, is_initiator: bool,
t: &tcp::KxTranscript, t: &tcp::KxTranscript,
) -> ResultType<()> { ) -> ResultType<()> {
if t.picked == 0 {
self.set_key(key);
return Ok(());
}
match self { match self {
#[cfg(feature = "webrtc")] #[cfg(feature = "webrtc")]
Stream::WebRTC(s) => { Stream::WebRTC(s) => {