diff --git a/boring/src/error.rs b/boring/src/error.rs index 08d8e82c..1d44357e 100644 --- a/boring/src/error.rs +++ b/boring/src/error.rs @@ -35,7 +35,8 @@ pub struct ErrorStack(Vec); impl ErrorStack { /// Pops the contents of the OpenSSL error stack, and returns it. - #[allow(clippy::must_use_candidate)] + #[corresponds(ERR_get_error_line_data)] + #[must_use = "Use ErrorStack::clear() to drop the error stack"] pub fn get() -> ErrorStack { let mut vec = vec![]; while let Some(err) = Error::get() { @@ -45,6 +46,7 @@ impl ErrorStack { } /// Pushes the errors back onto the OpenSSL error stack. + #[corresponds(ERR_put_error)] pub fn put(&self) { for error in self.errors() { error.put(); @@ -56,6 +58,14 @@ impl ErrorStack { pub(crate) fn internal_error(err: impl error::Error) -> Self { Self(vec![Error::new_internal(err.to_string())]) } + + /// Empties the current thread's error queue. + #[corresponds(ERR_clear_error)] + pub(crate) fn clear() { + unsafe { + ffi::ERR_clear_error(); + } + } } impl ErrorStack { @@ -120,7 +130,8 @@ static BORING_INTERNAL: &CStr = c"boring-rust"; impl Error { /// Pops the first error off the OpenSSL error stack. - #[allow(clippy::must_use_candidate)] + #[must_use = "Use ErrorStack::clear() to drop the error stack"] + #[corresponds(ERR_get_error_line_data)] pub fn get() -> Option { unsafe { ffi::init(); @@ -153,6 +164,7 @@ impl Error { } /// Pushes the error back onto the OpenSSL error stack. + #[corresponds(ERR_put_error)] pub fn put(&self) { unsafe { ffi::ERR_put_error( diff --git a/boring/src/sign.rs b/boring/src/sign.rs index 3a4a7e8f..b87e6010 100644 --- a/boring/src/sign.rs +++ b/boring/src/sign.rs @@ -478,7 +478,7 @@ impl<'a> Verifier<'a> { match r { 1 => Ok(true), 0 => { - ErrorStack::get(); // discard error stack + ErrorStack::clear(); // discard error stack Ok(false) } _ => Err(ErrorStack::get()), @@ -500,7 +500,7 @@ impl<'a> Verifier<'a> { match r { 1 => Ok(true), 0 => { - ErrorStack::get(); + ErrorStack::clear(); Ok(false) } _ => Err(ErrorStack::get()), diff --git a/boring/src/x509/mod.rs b/boring/src/x509/mod.rs index b9680e65..52f24fca 100644 --- a/boring/src/x509/mod.rs +++ b/boring/src/x509/mod.rs @@ -815,7 +815,7 @@ impl X509 { if ffi::ERR_GET_LIB(err) == ffi::ERR_LIB_PEM.0.try_into().unwrap() && ffi::ERR_GET_REASON(err) == ffi::PEM_R_NO_START_LINE { - ffi::ERR_clear_error(); + ErrorStack::clear(); break; }