Skip to content

Commit

Permalink
add tls ClientConfig::merge
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenDC committed Oct 22, 2024
1 parent 781ad48 commit b0f8dcd
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion rama-net/src/tls/client/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::ClientHelloExtension;
use super::{merge_client_hello_lists, ClientHelloExtension};
use crate::tls::{CipherSuite, CompressionAlgorithm, DataEncoding, KeyLogIntent};

#[derive(Debug, Clone, Default)]
Expand All @@ -23,6 +23,37 @@ pub struct ClientConfig {
pub key_logger: Option<KeyLogIntent>,
}

impl ClientConfig {
/// Merge this [`ClientConfig`] with aother one.
pub fn merge(&mut self, other: ClientConfig) {
if let Some(cipher_suites) = other.cipher_suites {
self.cipher_suites = Some(cipher_suites);
}

if let Some(compression_algorithms) = other.compression_algorithms {
self.compression_algorithms = Some(compression_algorithms);
}

self.extensions = match (self.extensions.take(), other.extensions) {
(Some(our_ext), Some(other_ext)) => Some(merge_client_hello_lists(our_ext, other_ext)),
(None, Some(other_ext)) => Some(other_ext),
(maybe_our_ext, None) => maybe_our_ext,
};

if let Some(server_verify_mode) = other.server_verify_mode {
self.server_verify_mode = Some(server_verify_mode);
}

if let Some(client_auth) = other.client_auth {
self.client_auth = Some(client_auth);
}

if let Some(key_logger) = other.key_logger {
self.key_logger = Some(key_logger);
}
}
}

#[derive(Debug, Clone)]
/// The kind of client auth to be used.
pub enum ClientAuth {
Expand Down

0 comments on commit b0f8dcd

Please sign in to comment.