1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use Error;
/// Errors that can occur during key generation, encryption, or decryption.
///
/// | Variant | When it happens | Typical fix |
/// | --- | --- | --- |
/// | `Io` | Filesystem or I/O failure | Check paths/permissions and retry |
/// | `ChaCha20Poly1305Error` | Symmetric encryption/decryption failed (bad tag, nonce issues) | Verify key, input integrity, and nonce uniqueness |
/// | `Argon2Error` | Password hashing/KDF failed | Ensure parameters are valid and memory is sufficient |
/// | `OpensslError` | Asymmetric operations failed | Validate PEM/keys; confirm OpenSSL availability |
/// | `WalkDirError` | Directory traversal failed | Check directory existence and permissions |
/// | `ZipError` | Zipping/unzipping archive failed | Inspect archive; ensure disk space |
/// | `ReedSolomonError` | Error-correction coding failed | Check shard completeness/integrity |
/// | `BinCodeEncodeError` / `BinCodeDecodeError` | Serialization/deserialization failed | Ensure input format matches expectation |
/// | `TryFromSliceError` | Byte slice could not be converted | Confirm buffer sizes |
/// | `EncryptionDecryptionError` | High-level guard for crypto failures | Recheck keys/passwords and inputs |
/// | `InputPath` | Missing input file or folder | Provide an existing path |
/// | `Message` | Catch-all with human-readable context | Inspect message for details |
///
/// # Examples
///
/// ```rust
/// use ferrocrypt::{symmetric_encryption, CryptoError, secrecy::SecretString};
///
/// fn example() -> Result<(), CryptoError> {
/// let passphrase = SecretString::from("test".to_string());
/// // This will fail with CryptoError::InputPath if file doesn't exist
/// match symmetric_encryption("./missing.txt", "./out", &passphrase, false) {
/// Ok(result) => println!("{}", result),
/// Err(CryptoError::Io(e)) => eprintln!("I/O error: {}", e),
/// Err(CryptoError::InputPath(msg)) => eprintln!("Missing input: {}", msg),
/// Err(e) => eprintln!("Other error: {}", e),
/// }
/// Ok(())
/// }
/// ```
// We must manually implement serde::Serialize for `tauri`