prisma / tiberius

TDS 7.2+ (Microsoft SQL Server) driver for Rust
Apache License 2.0
311 stars 113 forks source link

`Config::trust_cert_ca` should take Into<PathBuf> instead of ToString #336

Open olback opened 3 months ago

olback commented 3 months ago

The Config::trust_cert_ca method currently takes a path-parameter that looks like this: path: impl ToString which then gets converted to a PathBuf. Is there a reason the trust_cert_ca method doesn't take a PathBuf directly? I'd argue it would be more correct since there are valid paths that are not valid UTF-8 strings.

Current impl:

pub fn trust_cert_ca(&mut self, path: impl ToString) {
    if let TrustConfig::TrustAll = &self.trust {
        panic!("'trust_cert' and 'trust_cert_ca' are mutual exclusive! Only use one.")
    } else {
        self.trust = TrustConfig::CaCertificateLocation(PathBuf::from(path.to_string()))
    }
}

Proposed impl:

pub fn trust_cert_ca(&mut self, path: impl Into<PathBuf>) {
    if let TrustConfig::TrustAll = &self.trust {
        panic!("'trust_cert' and 'trust_cert_ca' are mutual exclusive! Only use one.")
    } else {
        self.trust = TrustConfig::CaCertificateLocation(path.into())
    }
}

I'd be happy to send a PR!