diff --git a/Cargo.toml b/Cargo.toml index ac6dd9a4..4206c3fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/cache.rs b/src/cache.rs index 42f0563c..96894c8d 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -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 { diff --git a/src/callbacks.rs b/src/callbacks.rs index 7d3da5cc..50e79ec6 100644 --- a/src/callbacks.rs +++ b/src/callbacks.rs @@ -64,11 +64,8 @@ impl AlpnCallbackConfig { /// /// Returns the selected ALPN, or None, or an error. pub fn invoke(&self, offer: &[u8]) -> Result>, 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(); @@ -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(); @@ -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(); @@ -192,11 +183,8 @@ pub fn invoke_session_new_callback( callback: SSL_CTX_new_session_cb, sess: Arc>, ) -> bool { - let callback = match callback { - Some(callback) => callback, - None => { - return false; - } + let Some(callback) = callback else { + return false; }; let ssl = SslCallbackContext::ssl_ptr(); @@ -215,12 +203,7 @@ pub fn invoke_session_get_callback( callback: SSL_CTX_sess_get_cb, id: &[u8], ) -> Option>> { - let callback = match callback { - Some(callback) => callback, - None => { - return None; - } - }; + let callback = callback?; let ssl_ptr = SslCallbackContext::ssl_ptr(); let mut copy = 1; @@ -244,11 +227,8 @@ pub fn invoke_session_remove_callback( ssl_ctx: *mut SSL_CTX, sess: Arc>, ) { - 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; diff --git a/src/conf.rs b/src/conf.rs index ebd586c0..3ac20584 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -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) { @@ -85,9 +82,8 @@ impl SslConfigCtx { } fn min_protocol(&mut self, proto: Option<&str>) -> Result { - 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 { @@ -105,9 +101,8 @@ impl SslConfigCtx { } fn max_protocol(&mut self, proto: Option<&str>) -> Result { - 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 { @@ -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() { @@ -176,9 +170,8 @@ impl SslConfigCtx { } fn certificate(&mut self, path: Option<&str>) -> Result { - 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)?; @@ -201,9 +194,8 @@ impl SslConfigCtx { } fn private_key(&mut self, path: Option<&str>) -> Result { - 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)?; @@ -221,9 +213,8 @@ impl SslConfigCtx { } fn verify_ca_path(&mut self, path: Option<&str>) -> Result { - let path = match path { - Some(path) => path, - None => return Ok(ActionResult::ValueRequired), + let Some(path) = path else { + return Ok(ActionResult::ValueRequired); }; match &self.state { @@ -242,9 +233,8 @@ impl SslConfigCtx { } fn verify_ca_file(&mut self, path: Option<&str>) -> Result { - let path = match path { - Some(path) => path, - None => return Ok(ActionResult::ValueRequired), + let Some(path) = path else { + return Ok(ActionResult::ValueRequired); }; match &self.state { @@ -280,9 +270,8 @@ impl SslConfigCtx { } fn options(&mut self, opts: Option<&str>) -> Result { - 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()) { @@ -379,7 +368,7 @@ pub(super) enum ValueType { impl From for c_int { fn from(value: ValueType) -> Self { - value as i32 + value as Self } } @@ -463,7 +452,7 @@ enum ActionResult { impl From for c_int { fn from(value: ActionResult) -> Self { - value as c_int + value as Self } } @@ -514,7 +503,7 @@ impl Flags { } impl From for c_uint { - fn from(flags: Flags) -> c_uint { + fn from(flags: Flags) -> Self { flags.0 } } diff --git a/src/entry.rs b/src/entry.rs index 9454c518..77c32a4f 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -121,7 +121,7 @@ entry! { impl Castable for SSL_METHOD { type Ownership = OwnershipRef; - type RustType = SSL_METHOD; + type RustType = Self; } pub type SSL_CTX = crate::SslContext; @@ -424,15 +424,12 @@ entry! { protos_len: c_uint, ) -> MysteriouslyOppositeReturnValue { let ctx = try_clone_arc!(ctx); - let slice = try_slice!(protos, protos_len); + let slice = try_slice!(protos, c_uint_into_usize(protos_len)); - let alpn = match crate::parse_alpn(slice) { - Some(alpn) => alpn, - None => { - // nb. openssl doesn't add anything to the error stack - // in this case. - return Error::bad_data("invalid alpn protocols").raise().into(); - } + let Some(alpn) = crate::parse_alpn(slice) else { + // nb. openssl doesn't add anything to the error stack + // in this case. + return Error::bad_data("invalid alpn protocols").raise().into(); }; ctx.get_mut().set_alpn_offer(alpn); @@ -689,7 +686,7 @@ entry! { sid_ctx: *const c_uchar, sid_ctx_len: c_uint, ) -> c_int { - let sid_ctx = try_slice!(sid_ctx, sid_ctx_len); + let sid_ctx = try_slice!(sid_ctx, c_uint_into_usize(sid_ctx_len)); if sid_ctx.len() > SSL_MAX_SID_CTX_LENGTH { return Error::not_supported("excess sid_ctx_len").raise().into(); } @@ -757,7 +754,7 @@ entry! { impl Castable for SSL_CTX { type Ownership = OwnershipArc; - type RustType = NotThreadSafe; + type RustType = NotThreadSafe; } pub type SSL = crate::Ssl; @@ -766,18 +763,14 @@ entry! { pub fn _SSL_new(ctx: *mut SSL_CTX) -> *mut SSL { let ctx = try_clone_arc!(ctx); - let ssl = match crate::Ssl::new(ctx.clone(), ctx.get()).ok() { - Some(ssl) => ssl, - None => return ptr::null_mut(), + let Some(ssl) = crate::Ssl::new(ctx.clone(), ctx.get()).ok() else { + return ptr::null_mut(); }; let out = to_arc_mut_ptr(NotThreadSafe::new(ssl)); - let ex_data = match ExData::new_ssl(out) { - None => { - _SSL_free(out); - return ptr::null_mut(); - } - Some(ex_data) => ex_data, + let Some(ex_data) = ExData::new_ssl(out) else { + _SSL_free(out); + return ptr::null_mut(); }; // safety: we just made this object, the pointer must be valid. @@ -937,15 +930,12 @@ entry! { protos_len: c_uint, ) -> MysteriouslyOppositeReturnValue { let ssl = try_clone_arc!(ssl); - let slice = try_slice!(protos, protos_len); + let slice = try_slice!(protos, c_uint_into_usize(protos_len)); - let alpn = match crate::parse_alpn(slice) { - Some(alpn) => alpn, - None => { - // nb. openssl doesn't add anything to the error stack - // in this case. - return Error::bad_data("invalid alpn protocols").raise().into(); - } + let Some(alpn) = crate::parse_alpn(slice) else { + // nb. openssl doesn't add anything to the error stack + // in this case. + return Error::bad_data("invalid alpn protocols").raise().into(); }; ssl.get_mut().set_alpn_offer(alpn); @@ -1131,8 +1121,8 @@ entry! { ERROR } Ok(result) => match result { - ShutdownResult::Sent => 0 as c_int, - ShutdownResult::Received => 1 as c_int, + ShutdownResult::Sent => 0, + ShutdownResult::Received => 1, }, } } @@ -1170,7 +1160,7 @@ entry! { entry! { pub fn _SSL_get_error(ssl: *const SSL, _ret_code: c_int) -> c_int { - try_clone_arc!(ssl).get_mut().get_error() as c_int + try_clone_arc!(ssl).get_mut().get_error() } } @@ -1489,7 +1479,7 @@ entry! { impl Castable for SSL { type Ownership = OwnershipArc; - type RustType = NotThreadSafe; + type RustType = NotThreadSafe; } type SSL_CIPHER = crate::SslCipher; @@ -1571,9 +1561,12 @@ entry! { entry! { pub fn _SSL_CIPHER_description( cipher: *const SSL_CIPHER, - mut buf: *mut c_char, - mut size: c_int, + buf: *mut c_char, + size: c_int, ) -> *mut c_char { + // rebind inside `ffi_panic_boundary` closure to make `unused_assignments` lint + // more accurate + let mut buf = buf; let description = try_ref_from_ptr!(cipher).description; let required_len = description.to_bytes_with_nul().len(); @@ -1587,13 +1580,12 @@ entry! { return allocd; } buf = allocd; - size = required_len as i32; } else if size < (required_len as i32) { return ptr::null_mut(); } unsafe { - ptr::copy_nonoverlapping(description.as_ptr(), buf, required_len as usize); + ptr::copy_nonoverlapping(description.as_ptr(), buf, required_len); }; buf } @@ -1601,7 +1593,7 @@ entry! { impl Castable for SSL_CIPHER { type Ownership = OwnershipRef; - type RustType = SSL_CIPHER; + type RustType = Self; } entry! { @@ -1613,8 +1605,8 @@ entry! { client: *const c_uchar, client_len: c_uint, ) -> c_int { - let server = try_slice!(server, server_len); - let client = try_slice!(client, client_len); + let server = try_slice!(server, c_uint_into_usize(server_len)); + let client = try_slice!(client, c_uint_into_usize(client_len)); if out.is_null() || out_len.is_null() { return 0; @@ -1732,7 +1724,7 @@ entry! { sid_ctx: *const c_uchar, sid_ctx_len: c_uint, ) -> c_int { - let slice = try_slice!(sid_ctx, sid_ctx_len); + let slice = try_slice!(sid_ctx, c_uint_into_usize(sid_ctx_len)); if slice.len() > SSL_MAX_SID_CTX_LENGTH { return Error::not_supported("excess sid_ctx_len").raise().into(); } @@ -1759,14 +1751,17 @@ entry! { .into(); } + let Ok(length) = usize::try_from(length) else { + return Error::bad_data("d2i_SSL_SESSION with negative length") + .raise() + .into(); + }; + let ptr = unsafe { ptr::read(pp) }; let slice = try_slice!(ptr, length); - let (sess, rest) = match SSL_SESSION::decode(slice) { - Some(r) => r, - None => { - return Error::bad_data("cannot decode SSL_SESSION").raise().into(); - } + let Some((sess, rest)) = SSL_SESSION::decode(slice) else { + return Error::bad_data("cannot decode SSL_SESSION").raise().into(); }; let consumed_bytes = slice.len() - rest.len(); @@ -1800,7 +1795,7 @@ entry! { impl Castable for SSL_SESSION { type Ownership = OwnershipArc; - type RustType = NotThreadSafe; + type RustType = NotThreadSafe; } entry! { @@ -1889,7 +1884,7 @@ pub type SSL_CONF_CTX = conf::SslConfigCtx; impl Castable for SSL_CONF_CTX { type Ownership = OwnershipBox; // SSL_CONF_CTX does not do reference counting. - type RustType = NotThreadSafe; + type RustType = NotThreadSafe; } entry! { @@ -2474,6 +2469,13 @@ entry_stub! { // --------------------- +fn c_uint_into_usize(v: c_uint) -> usize { + const { + assert!(size_of::() <= size_of::()); + } + v as usize +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/error.rs b/src/error.rs index 4852b46e..271bda9a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -31,17 +31,17 @@ enum Reason { } impl From for c_int { - fn from(r: Reason) -> c_int { + fn from(r: Reason) -> Self { use Reason::*; match r { // see `err.h.in` for magic numbers. - PassedNullParameter => (ERR_RFLAG_FATAL as i32) | ERR_RFLAG_COMMON | 258, - InternalError => (ERR_RFLAG_FATAL as i32) | ERR_RFLAG_COMMON | 259, - OperationFailed => (ERR_RFLAG_FATAL as i32) | ERR_RFLAG_COMMON | 263, + PassedNullParameter => (ERR_RFLAG_FATAL as Self) | ERR_RFLAG_COMMON | 258, + InternalError => (ERR_RFLAG_FATAL as Self) | ERR_RFLAG_COMMON | 259, + OperationFailed => (ERR_RFLAG_FATAL as Self) | ERR_RFLAG_COMMON | 263, Unsupported => ERR_RFLAG_COMMON | 268, WouldBlock => 0, // `sslerr.h` - Alert(alert) => 1000 + u8::from(alert) as c_int, + Alert(alert) => 1000 + u8::from(alert) as Self, } } } @@ -193,7 +193,7 @@ impl From for usize { impl From for MysteriouslyOppositeReturnValue { fn from(_: Error) -> Self { // for a small subset of OpenSSL functions (return 1 on error) - MysteriouslyOppositeReturnValue::Error + Self::Error } } @@ -232,7 +232,7 @@ impl From for () { } impl From for crate::entry::SSL_verify_cb { - fn from(_: Error) -> crate::entry::SSL_verify_cb { + fn from(_: Error) -> Self { None } } diff --git a/src/evp_pkey.rs b/src/evp_pkey.rs index aaa82f25..c7abdc99 100644 --- a/src/evp_pkey.rs +++ b/src/evp_pkey.rs @@ -261,7 +261,7 @@ impl SignCtx { } }; - Some(SignCtx { md_ctx, pkey_ctx }) + Some(Self { md_ctx, pkey_ctx }) } fn set_signature_md(&mut self, md: *const EVP_MD) -> Option<()> { diff --git a/src/ffi.rs b/src/ffi.rs index 9ddc8bdb..01b8b5d1 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -418,7 +418,7 @@ macro_rules! try_slice { if $ptr.is_null() { return $crate::error::Error::null_pointer().raise().into(); } else { - unsafe { ::core::slice::from_raw_parts($ptr, $count as usize) } + unsafe { ::core::slice::from_raw_parts($ptr, $count) } } }; } diff --git a/src/lib.rs b/src/lib.rs index 2f4defb5..32258743 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,7 +103,7 @@ pub struct SslCipher { } impl SslCipher { - pub fn find_by_id(id: CipherSuite) -> Option<&'static SslCipher> { + pub fn find_by_id(id: CipherSuite) -> Option<&'static Self> { match id { CipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 => { Some(&TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256) @@ -283,7 +283,7 @@ impl SslSession { let time_out = self.time_out.to_le_bytes(); let mut ret = Vec::with_capacity( - SslSession::MAGIC.len() + Self::MAGIC.len() + id_len.len() + self.id.0.len() + value_len.len() @@ -293,7 +293,7 @@ impl SslSession { + creation_time.len() + time_out.len(), ); - ret.extend_from_slice(SslSession::MAGIC); + ret.extend_from_slice(Self::MAGIC); ret.extend_from_slice(&id_len); ret.extend_from_slice(&self.id.0); ret.extend_from_slice(&value_len); @@ -325,11 +325,11 @@ impl SslSession { u64::from_le_bytes(slice.try_into().unwrap()) } - let usize_len = mem::size_of::(); - let u64_len = mem::size_of::(); + let usize_len = size_of::(); + let u64_len = size_of::(); - let (magic, slice) = split_at(slice, SslSession::MAGIC.len())?; - if magic != SslSession::MAGIC { + let (magic, slice) = split_at(slice, Self::MAGIC.len())?; + if magic != Self::MAGIC { return None; } let (id_len, slice) = split_at(slice, usize_len)?; @@ -381,7 +381,7 @@ impl SslSession { } } -impl PartialOrd for SslSession { +impl PartialOrd for SslSession { fn partial_cmp(&self, other: &Self) -> Option { Some(self.id.cmp(&other.id)) } @@ -393,7 +393,7 @@ impl Ord for SslSession { } } -impl PartialEq for SslSession { +impl PartialEq for SslSession { fn eq(&self, other: &Self) -> bool { self.id == other.id } @@ -436,7 +436,7 @@ pub struct SslContext { raw_options: u64, verify_mode: VerifyMode, verify_depth: c_int, - verify_x509_store: x509::OwnedX509Store, + verify_x509_store: OwnedX509Store, alpn: Vec>, default_cert_file: Option, default_cert_dir: Option, @@ -478,10 +478,7 @@ impl SslContext { } } - fn complete_construction( - &mut self, - pointer_to_self: *mut entry::SSL_CTX, - ) -> Result<(), error::Error> { + fn complete_construction(&mut self, pointer_to_self: *mut Self) -> Result<(), error::Error> { self.caches.set_pointer_to_owning_ssl_ctx(pointer_to_self); self.ex_data = ex_data::ExData::new_ssl_ctx(pointer_to_self) @@ -749,7 +746,7 @@ struct Ssl { verify_mode: VerifyMode, verify_depth: c_int, verify_server_name: Option>, - verify_x509_store: x509::OwnedX509Store, + verify_x509_store: OwnedX509Store, alpn: Vec>, alpn_callback: callbacks::AlpnCallbackConfig, cert_callback: callbacks::CertCallbackConfig, @@ -1086,9 +1083,8 @@ impl Ssl { fn invoke_accepted_callbacks(&mut self) -> Result<(), error::Error> { // called on transition from `Accepting` -> `Accepted` - let accepted = match &self.conn { - ConnState::Accepted(accepted) => accepted, - _ => unreachable!(), + let ConnState::Accepted(accepted) = &self.conn else { + unreachable!(); }; self.server_name = accepted @@ -1160,9 +1156,8 @@ impl Ssl { let cache = self.ctx.get_mut().caches.get_server(); config.session_storage = cache.clone(); - let accepted = match mem::replace(&mut self.conn, ConnState::Nothing) { - ConnState::Accepted(accepted) => accepted, - _ => unreachable!(), + let ConnState::Accepted(accepted) = mem::replace(&mut self.conn, ConnState::Nothing) else { + unreachable!(); }; // TODO: send alert @@ -1241,9 +1236,8 @@ impl Ssl { } fn try_io(&mut self) -> Result<(), error::Error> { - let bio = match self.bio.as_mut() { - Some(bio) => bio, - None => return Ok(()), // investigate OpenSSL behaviour without a BIO + let Some(bio) = self.bio.as_mut() else { + return Ok(()); // investigate OpenSSL behaviour without a BIO }; match &mut self.conn { @@ -1338,23 +1332,20 @@ impl Ssl { } fn init_peer_cert(&mut self) { - let conn = match self.conn() { - Some(conn) => conn, - None => return, + let Some(conn) = self.conn() else { + return; }; - let certs = match conn.peer_certificates() { - Some(certs) => certs, - None => return, + let Some(certs) = conn.peer_certificates() else { + return; }; let mut stack = x509::OwnedX509Stack::empty(); let mut peer_cert = None; for (i, cert) in certs.iter().enumerate() { - let converted = match x509::OwnedX509::parse_der(cert.as_ref()) { - Some(converted) => converted, - None => return, + let Some(converted) = x509::OwnedX509::parse_der(cert.as_ref()) else { + return; }; if i == 0 { @@ -1448,7 +1439,7 @@ impl Ssl { } } - fn load_verify_certs(ctx: &SslContext) -> Result { + fn load_verify_certs(ctx: &SslContext) -> Result { // If verify_roots isn't empty then it was configured with `SSL_CTX_load_verify_file` // or `SSL_CTX_load_verify_dir` and we should use it as-is. if !ctx.verify_x509_store.is_empty() { @@ -1456,7 +1447,7 @@ impl Ssl { } // Otherwise, try to load the default cert file or cert dir. - let mut verify_roots = x509::OwnedX509Store::default(); + let mut verify_roots = OwnedX509Store::default(); if let Some(default_cert_file) = &ctx.default_cert_file { verify_roots.add_from_files([default_cert_file.to_path_buf()])?; @@ -1555,17 +1546,17 @@ impl HandshakeState { // nb. // 1. openssl 3 behaviour for SSL_in_before or SSL_in_init does not match docs // 2. SSL_in_init becomes 1 on sending a fatal alert - HandshakeState::Before - | HandshakeState::Error - | HandshakeState::ClientAwaitingServerHello - | HandshakeState::ServerAwaitingClientHello => true, + Self::Before + | Self::Error + | Self::ClientAwaitingServerHello + | Self::ServerAwaitingClientHello => true, _ => false, } } } impl From for c_uint { - fn from(hs: HandshakeState) -> c_uint { + fn from(hs: HandshakeState) -> Self { match hs { HandshakeState::Before => 0, HandshakeState::Finished => 1, @@ -1609,39 +1600,39 @@ impl ShutdownFlags { const PRIV_QUIET: i32 = 4; fn is_sent(&self) -> bool { - self.0 & ShutdownFlags::SENT == ShutdownFlags::SENT + self.0 & Self::SENT == Self::SENT } fn is_received(&self) -> bool { - self.0 & ShutdownFlags::RECEIVED == ShutdownFlags::RECEIVED + self.0 & Self::RECEIVED == Self::RECEIVED } fn set_sent(&mut self) { - self.0 |= ShutdownFlags::SENT; + self.0 |= Self::SENT; } fn set_received(&mut self) { - self.0 |= ShutdownFlags::RECEIVED; + self.0 |= Self::RECEIVED; } fn set(&mut self, flags: i32) { - self.0 |= flags & ShutdownFlags::PUBLIC; + self.0 |= flags & Self::PUBLIC; } fn get(&self) -> i32 { - self.0 & ShutdownFlags::PUBLIC + self.0 & Self::PUBLIC } fn set_quiet(&mut self, enabled: bool) { if enabled { - self.0 |= ShutdownFlags::PRIV_QUIET; + self.0 |= Self::PRIV_QUIET; } else { - self.0 &= !ShutdownFlags::PRIV_QUIET; + self.0 &= !Self::PRIV_QUIET; } } fn quiet(&self) -> bool { - self.0 & ShutdownFlags::PRIV_QUIET == ShutdownFlags::PRIV_QUIET + self.0 & Self::PRIV_QUIET == Self::PRIV_QUIET } } @@ -1655,20 +1646,20 @@ impl VerifyMode { // other flags not mentioned here are not implemented. pub fn client_must_verify_server(&self) -> bool { - self.0 & VerifyMode::PEER == VerifyMode::PEER + self.0 & Self::PEER == Self::PEER } pub fn server_must_attempt_client_auth(&self) -> bool { - self.0 & VerifyMode::PEER == VerifyMode::PEER + self.0 & Self::PEER == Self::PEER } pub fn server_must_verify_client(&self) -> bool { - let bitmap = VerifyMode::PEER | VerifyMode::FAIL_IF_NO_PEER_CERT; + let bitmap = Self::PEER | Self::FAIL_IF_NO_PEER_CERT; self.0 & bitmap == bitmap } pub fn server_should_verify_client_but_allow_anon(&self) -> bool { - self.0 & (VerifyMode::PEER | VerifyMode::FAIL_IF_NO_PEER_CERT) == VerifyMode::PEER + self.0 & (Self::PEER | Self::FAIL_IF_NO_PEER_CERT) == Self::PEER } } diff --git a/src/not_thread_safe.rs b/src/not_thread_safe.rs index 4b87375d..dcd6e94c 100644 --- a/src/not_thread_safe.rs +++ b/src/not_thread_safe.rs @@ -49,7 +49,7 @@ impl Ord for NotThreadSafe { } impl + Ord> PartialOrd for NotThreadSafe { - fn partial_cmp(&self, other: &NotThreadSafe) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.get().cmp(other.get())) } }