mysql_async/opts/
native_tls_opts.rs
1#![cfg(feature = "native-tls-tls")]
2
3use std::borrow::Cow;
4
5use native_tls::Identity;
6
7use super::PathOrBuf;
8
9#[derive(Debug, Clone, PartialEq, Eq, Hash)]
10pub struct ClientIdentity {
11 pkcs12_archive: PathOrBuf<'static>,
12 password: Option<Cow<'static, str>>,
13}
14
15impl ClientIdentity {
16 pub fn new(pkcs12_archive: PathOrBuf<'static>) -> Self {
18 Self {
19 pkcs12_archive,
20 password: None,
21 }
22 }
23
24 pub fn with_pkcs12_archive(mut self, pkcs12_archive: PathOrBuf<'static>) -> Self {
26 self.pkcs12_archive = pkcs12_archive;
27 self
28 }
29
30 pub fn with_password<T>(mut self, pass: T) -> Self
32 where
33 T: Into<Cow<'static, str>>,
34 {
35 self.password = Some(pass.into());
36 self
37 }
38
39 pub fn pkcs12_archive(&self) -> PathOrBuf<'_> {
41 self.pkcs12_archive.borrow()
42 }
43
44 pub fn password(&self) -> Option<&str> {
46 self.password.as_ref().map(AsRef::as_ref)
47 }
48
49 pub(crate) async fn load(&self) -> crate::Result<Identity> {
50 let der = self.pkcs12_archive.read().await?;
51 let password = self.password().unwrap_or_default();
52 Ok(Identity::from_pkcs12(der.as_ref(), password)?)
53 }
54}