Skip to content

Commit a9356fc

Browse files
elmarcoCBenoit
authored andcommitted
docs(example/server): refactor acceptor() to be a TlsIdentityCtx method
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent 5381b24 commit a9356fc

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

crates/ironrdp/examples/server.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,18 @@ impl TlsIdentityCtx {
169169
pub_key,
170170
})
171171
}
172-
}
173172

174-
fn acceptor(
175-
cert: rustls::pki_types::CertificateDer<'static>,
176-
priv_key: rustls::pki_types::PrivateKeyDer<'static>,
177-
) -> anyhow::Result<TlsAcceptor> {
178-
let mut server_config = rustls::ServerConfig::builder()
179-
.with_no_client_auth()
180-
.with_single_cert(vec![cert], priv_key)
181-
.context("bad certificate/key")?;
173+
fn make_acceptor(&self) -> anyhow::Result<TlsAcceptor> {
174+
let mut server_config = rustls::ServerConfig::builder()
175+
.with_no_client_auth()
176+
.with_single_cert(vec![self.cert.clone()], self.priv_key.clone_key())
177+
.context("bad certificate/key")?;
182178

183-
// This adds support for the SSLKEYLOGFILE env variable (https://wiki.wireshark.org/TLS#using-the-pre-master-secret)
184-
server_config.key_log = Arc::new(rustls::KeyLogFile::new());
179+
// This adds support for the SSLKEYLOGFILE env variable (https://wiki.wireshark.org/TLS#using-the-pre-master-secret)
180+
server_config.key_log = Arc::new(rustls::KeyLogFile::new());
185181

186-
Ok(TlsAcceptor::from(Arc::new(server_config)))
182+
Ok(TlsAcceptor::from(Arc::new(server_config)))
183+
}
187184
}
188185

189186
#[derive(Clone, Debug)]
@@ -389,7 +386,7 @@ async fn run(
389386

390387
let server_builder = if let Some((cert_path, key_path)) = cert.as_deref().zip(key.as_deref()) {
391388
let identity = TlsIdentityCtx::init_from_paths(cert_path, key_path).context("failed to init TLS identity")?;
392-
let acceptor = acceptor(identity.cert, identity.priv_key).context("failed to build TLS acceptor")?;
389+
let acceptor = identity.make_acceptor().context("failed to build TLS acceptor")?;
393390

394391
if hybrid {
395392
server_builder.with_hybrid(acceptor, identity.pub_key)

0 commit comments

Comments
 (0)