Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for setting client certificate and key from bytes #2646

Merged
merged 5 commits into from Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions sqlx-mysql/src/options/mod.rs
Expand Up @@ -213,6 +213,21 @@ impl MySqlConnectOptions {
self
}

/// Sets the SSL client certificate from a byte slice.
abonander marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Example
///
/// ```rust
/// # use sqlx_core::mysql::{MySqlSslMode, MySqlConnectOptions};
/// let options = MySqlConnectOptions::new()
/// .ssl_mode(MySqlSslMode::VerifyCa)
/// .ssl_client_cert_from_bytes(vec![]);
/// ```
pub fn ssl_client_cert_from_bytes(mut self, cert: impl AsRef<[u8]>) -> Self {
self.ssl_client_cert = Some(CertificateInput::Inline(cert.as_ref().to_vec()));
self
}

/// Sets the name of a file containing SSL client key.
///
/// # Example
Expand All @@ -228,6 +243,21 @@ impl MySqlConnectOptions {
self
}

/// Sets the SSL client key from a byte slice.
abonander marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Example
///
/// ```rust
/// # use sqlx_core::mysql::{MySqlSslMode, MySqlConnectOptions};
/// let options = MySqlConnectOptions::new()
/// .ssl_mode(MySqlSslMode::VerifyCa)
/// .ssl_client_key_from_bytes(vec![]);
/// ```
pub fn ssl_client_key_from_bytes(mut self, key: impl AsRef<[u8]>) -> Self {
self.ssl_client_key = Some(CertificateInput::Inline(key.as_ref().to_vec()));
self
}

/// Sets the capacity of the connection's statement cache in a number of stored
/// distinct statements. Caching is handled using LRU, meaning when the
/// amount of queries hits the defined limit, the oldest statement will get
Expand Down
32 changes: 32 additions & 0 deletions sqlx-postgres/src/options/mod.rs
Expand Up @@ -344,6 +344,22 @@ impl PgConnectOptions {
self
}

/// Sets the SSL client certificate from a byte slice.
abonander marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Example
///
/// ```rust
/// # use sqlx_core::postgres::{PgSslMode, PgConnectOptions};
/// let options = PgConnectOptions::new()
/// // Providing a CA certificate with less than VerifyCa is pointless
/// .ssl_mode(PgSslMode::VerifyCa)
/// .ssl_client_cert_from_bytes(vec![]);
/// ```
pub fn ssl_client_cert_from_bytes(mut self, cert: impl AsRef<[u8]>) -> Self {
self.ssl_client_cert = Some(CertificateInput::Inline(cert.as_ref().to_vec()));
self
}

/// Sets the name of a file containing SSL client key.
///
/// # Example
Expand All @@ -360,6 +376,22 @@ impl PgConnectOptions {
self
}

/// Sets the SSL client key from a byte slice.
abonander marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Example
///
/// ```rust
/// # use sqlx_core::postgres::{PgSslMode, PgConnectOptions};
/// let options = PgConnectOptions::new()
/// // Providing a CA certificate with less than VerifyCa is pointless
/// .ssl_mode(PgSslMode::VerifyCa)
/// .ssl_client_key_from_bytes(vec![]);
/// ```
pub fn ssl_client_key_from_bytes(mut self, key: impl AsRef<[u8]>) -> Self {
self.ssl_client_key = Some(CertificateInput::Inline(key.as_ref().to_vec()));
self
}

/// Sets PEM encoded trusted SSL Certificate Authorities (CA).
///
/// # Example
Expand Down