1pub mod config;
2pub mod regex;
3pub mod scanner;
4pub mod secret_type;
5
6pub use config::Config;
7pub use scanner::{FoundSecret, Scanner};
8pub use secret_type::SecretType;
9
10extern crate regex as extern_regex;
11
12use thiserror::Error;
13
14#[derive(Error, Debug)]
15pub enum MinosCodexError {
16 #[error("Failed to load configuration: {0}")]
17 ConfigLoadError(#[from] std::io::Error),
18 #[error("Failed to parse TOML: {0}")]
19 TomlParseError(#[from] toml::de::Error),
20 #[error("Invalid regex: {0}")]
21 RegexError(String),
22 #[error("Validation error: {0}")]
24 ValidationError(String),
25}
26
27pub fn create_scanner() -> Result<Scanner, MinosCodexError> {
28 let config = Config::load_from_embedded()?;
29 Ok(Scanner::new(config))
30}
31impl From<extern_regex::Error> for MinosCodexError {
32 fn from(err: extern_regex::Error) -> Self {
33 match err {
34 extern_regex::Error::Syntax(msg) => {
35 MinosCodexError::RegexError(format!("Syntax error: {}", msg))
36 }
37 extern_regex::Error::CompiledTooBig(size) => {
38 MinosCodexError::RegexError(format!("Compiled pattern too big: {} bytes", size))
39 }
40 _ => MinosCodexError::RegexError("Unhandled regex error".to_string()),
41 }
42 }
43}