feat: Split tls_key_password into a separate function

WHen configuring a PKCS12 certificate it is more useful to be able to
set this separately, as the `tls_client_key` function is never called.
This commit is contained in:
Vincent Ambo 2019-02-26 17:16:55 +01:00
parent 37dc54f2bf
commit 2349dd22c3

View file

@ -177,21 +177,24 @@ impl <'a> Request<'a> {
Ok(self) Ok(self)
} }
/// Configure a TLS client certificate key on the request with an /// Configure a TLS client certificate key on the request.
/// optional key passphrase.
/// ///
/// Note that this does **not** need to be called again for /// Note that this does **not** need to be called again for
/// PKCS12-encoded key pairs which are set via `tls_client_cert`. /// PKCS12-encoded key pairs which are set via `tls_client_cert`.
/// ///
/// Currently only PEM-encoded key files are supported. /// Currently only PEM-encoded key files are supported.
pub fn tls_client_key<P, S>(mut self, key: P, passphrase: Option<S>) pub fn tls_client_key<P: AsRef<Path>>(mut self, key: P) -> Result<Self, curl::Error> {
-> Result<Self, curl::Error>
where P: AsRef<Path>, S: AsRef<str> {
self.handle.ssl_key(key)?; self.handle.ssl_key(key)?;
if let Some(pass) = passphrase { Ok(self)
self.handle.key_password(pass.as_ref())?; }
}
/// Configure an encryption password for a TLS client certificate
/// key on the request.
///
/// This is required in case of an encrypted private key that
/// should be used.
pub fn tls_key_password(mut self, password: &str) -> Result<Self, curl::Error> {
self.handle.key_password(password)?;
Ok(self) Ok(self)
} }