neuron_encrypt_core/
error.rs1use thiserror::Error;
5
6#[derive(Error, Debug)]
8pub enum CryptoError {
9 #[error("File too small to be a valid Neuron Encrypt file")]
10 FileTooSmall,
11
12 #[error("Not a valid Neuron Encrypt file (bad magic bytes)")]
13 InvalidMagic,
14
15 #[error("Unsupported file format version: {0}")]
16 UnsupportedVersion(String),
17
18 #[error("Wrong password or corrupted file")]
19 DecryptionFailed,
20
21 #[error("Argon2id key derivation failed: {0}")]
22 Argon2Failed(String),
23
24 #[error("HKDF key expansion failed: {0}")]
25 HkdfFailed(String),
26
27 #[error("Encryption failed: {0}")]
28 EncryptionFailed(String),
29
30 #[error("File too large ({size_gb:.1} GB). Maximum supported size is ~{max_gb:.1} GB.")]
31 FileTooLarge { size_gb: f64, max_gb: f64 },
32
33 #[error("Destination file already exists: {0}")]
34 FileAlreadyExists(std::path::PathBuf),
35
36 #[error("Invalid destination path: {0}")]
37 InvalidDestination(std::path::PathBuf),
38
39 #[error("Source and destination must be different files: {0}")]
40 SourceAndDestinationSame(std::path::PathBuf),
41
42 #[error("I/O error: {0}")]
43 Io(#[from] std::io::Error),
44
45 #[error("Not a regular file: {0}")]
46 NotAFile(std::path::PathBuf),
47
48 #[error("Invalid salt length: expected {expected} bytes, got {actual}")]
49 InvalidSaltLength { expected: usize, actual: usize },
50
51 #[error("Invalid nonce length: expected {expected} bytes, got {actual}")]
52 InvalidNonceLength { expected: usize, actual: usize },
53
54 #[error("Passphrase too short (minimum {0} bytes required)")]
55 PassphraseTooShort(usize),
56
57 #[error("Legacy V2 file exceeds the 1 GB memory limit — re-encrypt with V3 format")]
58 LegacyFileTooLarge,
59
60 #[error("Operation cancelled by user")]
61 Cancelled,
62}
63
64pub type CryptoResult<T> = Result<T, CryptoError>;