pub struct CipherError { /* private fields */ }Expand description
Error returned by SegmentCipher implementations.
Deliberately minimal: the cipher operates on bytes, not files, so it has no
path or sequence context to carry. The segment I/O layer enriches this into
a crate::SegmentError::Cipher with the offending file’s path.
Construct with CipherError::msg for a plain message, or
CipherError::with_source when you want to preserve the underlying AEAD
(or other) error type for std::error::Error::source() chaining. The
fields are private so that adding context later is non-breaking.
Implementations§
Source§impl CipherError
impl CipherError
Sourcepub fn msg(message: impl Display) -> Self
pub fn msg(message: impl Display) -> Self
Construct a CipherError from anything displayable, with no
underlying cause.
§Example
use segment_buffer::CipherError;
let err = CipherError::msg("key not configured");
assert_eq!(err.to_string(), "key not configured");
assert!(std::error::Error::source(&err).is_none());Sourcepub fn with_source<E>(message: impl Display, source: E) -> Self
pub fn with_source<E>(message: impl Display, source: E) -> Self
Construct a CipherError that preserves the underlying error so
operators can inspect it via std::error::Error::source.
Use this when wrapping a typed error from an AEAD implementation
(aes_gcm::Error, chacha20poly1305::Error, …) so the original
failure is not erased behind a format!.
§Example
use segment_buffer::CipherError;
use std::fmt;
use std::error::Error;
/// A tiny typed error an AEAD crate might expose.
#[derive(Debug)]
struct AeadError;
impl fmt::Display for AeadError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("tag mismatch")
}
}
impl std::error::Error for AeadError {}
let err = CipherError::with_source("AES-GCM decryption failed", AeadError);
assert_eq!(err.to_string(), "AES-GCM decryption failed");
// The underlying cause is preserved via `source()`:
let src = err.source().expect("source should be set by with_source");
assert_eq!(src.to_string(), "tag mismatch");Trait Implementations§
Source§impl Clone for CipherError
impl Clone for CipherError
Source§impl Debug for CipherError
impl Debug for CipherError
Source§impl Display for CipherError
impl Display for CipherError
Source§impl Error for CipherError
impl Error for CipherError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()