Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ rustls = "0.23.27"

[dev-dependencies]
pretty_assertions = "1"

[lints.rust]
trivial_numeric_casts = "warn"
unused_import_braces = "warn"
unused_extern_crates = "warn"
unused_qualifications = "warn"

[lints.clippy]
manual_let_else = "warn"
use_self = "warn"
4 changes: 2 additions & 2 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ unsafe impl Send for CacheCallbacks {}
pub struct ExpiryTime(pub u64);

impl ExpiryTime {
pub fn calculate(now: TimeBase, life_time_secs: u64) -> ExpiryTime {
ExpiryTime(now.0.saturating_add(life_time_secs))
pub fn calculate(now: TimeBase, life_time_secs: u64) -> Self {
Self(now.0.saturating_add(life_time_secs))
}

pub fn in_past(&self, time: TimeBase) -> bool {
Expand Down
42 changes: 11 additions & 31 deletions src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ impl AlpnCallbackConfig {
///
/// Returns the selected ALPN, or None, or an error.
pub fn invoke(&self, offer: &[u8]) -> Result<Option<Vec<u8>>, Error> {
let callback = match self.cb {
Some(callback) => callback,
None => {
return Ok(None);
}
let Some(callback) = self.cb else {
return Ok(None);
};

let ssl = SslCallbackContext::ssl_ptr();
Expand Down Expand Up @@ -115,11 +112,8 @@ pub struct CertCallbackConfig {

impl CertCallbackConfig {
pub fn invoke(&self) -> Result<(), Error> {
let callback = match self.cb {
Some(callback) => callback,
None => {
return Ok(());
}
let Some(callback) = self.cb else {
return Ok(());
};
let ssl = SslCallbackContext::ssl_ptr();

Expand Down Expand Up @@ -150,11 +144,8 @@ pub struct ServerNameCallbackConfig {

impl ServerNameCallbackConfig {
pub fn invoke(&self) -> Result<(), Error> {
let callback = match self.cb {
Some(callback) => callback,
None => {
return Ok(());
}
let Some(callback) = self.cb else {
return Ok(());
};

let ssl = SslCallbackContext::ssl_ptr();
Expand Down Expand Up @@ -192,11 +183,8 @@ pub fn invoke_session_new_callback(
callback: SSL_CTX_new_session_cb,
sess: Arc<NotThreadSafe<SSL_SESSION>>,
) -> bool {
let callback = match callback {
Some(callback) => callback,
None => {
return false;
}
let Some(callback) = callback else {
return false;
};

let ssl = SslCallbackContext::ssl_ptr();
Expand All @@ -215,12 +203,7 @@ pub fn invoke_session_get_callback(
callback: SSL_CTX_sess_get_cb,
id: &[u8],
) -> Option<Arc<NotThreadSafe<SSL_SESSION>>> {
let callback = match callback {
Some(callback) => callback,
None => {
return None;
}
};
let callback = callback?;

let ssl_ptr = SslCallbackContext::ssl_ptr();
let mut copy = 1;
Expand All @@ -244,11 +227,8 @@ pub fn invoke_session_remove_callback(
ssl_ctx: *mut SSL_CTX,
sess: Arc<NotThreadSafe<SSL_SESSION>>,
) {
let callback = match callback {
Some(callback) => callback,
None => {
return;
}
let Some(callback) = callback else {
return;
};

let sess_ptr = Arc::into_raw(sess) as *mut SSL_SESSION;
Expand Down
53 changes: 21 additions & 32 deletions src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ impl SslConfigCtx {
}

pub(super) fn cmd(&mut self, cmd: &str, value: Option<&str>) -> c_int {
let command = match self.supported_command(cmd) {
Some(command) => command,
None => {
return -2; // "A return value of -2 means option is not recognised."
}
let Some(command) = self.supported_command(cmd) else {
return -2; // "A return value of -2 means option is not recognised."
};

match (command.action)(self, value) {
Expand Down Expand Up @@ -85,9 +82,8 @@ impl SslConfigCtx {
}

fn min_protocol(&mut self, proto: Option<&str>) -> Result<ActionResult, Error> {
let ver = match Self::parse_protocol_version(proto) {
Some(ver) => ver,
None => return Err(Error::bad_data("unrecognized protocol version")),
let Some(ver) = Self::parse_protocol_version(proto) else {
return Err(Error::bad_data("unrecognized protocol version"));
};

Ok(match &self.state {
Expand All @@ -105,9 +101,8 @@ impl SslConfigCtx {
}

fn max_protocol(&mut self, proto: Option<&str>) -> Result<ActionResult, Error> {
let ver = match Self::parse_protocol_version(proto) {
Some(ver) => ver,
None => return Err(Error::bad_data("unrecognized protocol version")),
let Some(ver) = Self::parse_protocol_version(proto) else {
return Err(Error::bad_data("unrecognized protocol version"));
};

Ok(match &self.state {
Expand All @@ -132,9 +127,8 @@ impl SslConfigCtx {
State::ApplyingToCtx(ctx) => ctx.get().verify_mode,
};

let raw_mode = match raw_mode {
Some(raw_mode) => raw_mode,
None => return Ok(ActionResult::ValueRequired),
let Some(raw_mode) = raw_mode else {
return Ok(ActionResult::ValueRequired);
};

if !self.flags.is_server() && !self.flags.is_client() {
Expand Down Expand Up @@ -176,9 +170,8 @@ impl SslConfigCtx {
}

fn certificate(&mut self, path: Option<&str>) -> Result<ActionResult, Error> {
let path = match path {
Some(path) => path,
None => return Ok(ActionResult::ValueRequired),
let Some(path) = path else {
return Ok(ActionResult::ValueRequired);
};
let cert_chain = use_cert_chain_file(path)?;

Expand All @@ -201,9 +194,8 @@ impl SslConfigCtx {
}

fn private_key(&mut self, path: Option<&str>) -> Result<ActionResult, Error> {
let path = match path {
Some(path) => path,
None => return Ok(ActionResult::ValueRequired),
let Some(path) = path else {
return Ok(ActionResult::ValueRequired);
};
let key = use_private_key_file(path, FILETYPE_PEM)?;

Expand All @@ -221,9 +213,8 @@ impl SslConfigCtx {
}

fn verify_ca_path(&mut self, path: Option<&str>) -> Result<ActionResult, Error> {
let path = match path {
Some(path) => path,
None => return Ok(ActionResult::ValueRequired),
let Some(path) = path else {
return Ok(ActionResult::ValueRequired);
};

match &self.state {
Expand All @@ -242,9 +233,8 @@ impl SslConfigCtx {
}

fn verify_ca_file(&mut self, path: Option<&str>) -> Result<ActionResult, Error> {
let path = match path {
Some(path) => path,
None => return Ok(ActionResult::ValueRequired),
let Some(path) = path else {
return Ok(ActionResult::ValueRequired);
};

match &self.state {
Expand Down Expand Up @@ -280,9 +270,8 @@ impl SslConfigCtx {
}

fn options(&mut self, opts: Option<&str>) -> Result<ActionResult, Error> {
let opts = match opts {
Some(path) => path,
None => return Ok(ActionResult::ValueRequired),
let Some(opts) = opts else {
return Ok(ActionResult::ValueRequired);
};

for part in opts.split(',').map(|part| part.trim()) {
Expand Down Expand Up @@ -379,7 +368,7 @@ pub(super) enum ValueType {

impl From<ValueType> for c_int {
fn from(value: ValueType) -> Self {
value as i32
value as Self
}
}

Expand Down Expand Up @@ -463,7 +452,7 @@ enum ActionResult {

impl From<ActionResult> for c_int {
fn from(value: ActionResult) -> Self {
value as c_int
value as Self
}
}

Expand Down Expand Up @@ -514,7 +503,7 @@ impl Flags {
}

impl From<Flags> for c_uint {
fn from(flags: Flags) -> c_uint {
fn from(flags: Flags) -> Self {
flags.0
}
}
Expand Down
Loading