diff --git a/Cargo.toml b/Cargo.toml index 486e4da11e..4f37b41229 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ edition = "2018" [dependencies] xxhrs = { version = "2.0.0", features = [] } #"random_entropy"] } +thiserror = "1.0" diff --git a/src/inputs/bytes.rs b/src/inputs/bytes.rs index 6bdd19456e..3ced8e4015 100644 --- a/src/inputs/bytes.rs +++ b/src/inputs/bytes.rs @@ -1,7 +1,8 @@ -use crate::inputs::Input; - use std::io::Error; +use crate::AflError; +use crate::inputs::Input; + #[derive(Clone, Debug, Default)] pub struct BytesInput { bytes: Vec, @@ -9,10 +10,10 @@ pub struct BytesInput { impl Input for BytesInput { - fn serialize(&self) -> Result<&[u8], Error> { + fn serialize(&self) -> Result<&[u8], AflError> { Ok(&self.bytes) } - fn deserialize(&mut self, buf: &[u8]) -> Result<(), Error> { + fn deserialize(&mut self, buf: &[u8]) -> Result<(), AflError> { self.bytes.truncate(0); self.bytes.extend_from_slice(buf); Ok(()) diff --git a/src/inputs/mod.rs b/src/inputs/mod.rs index f365f5ad5e..3583907086 100644 --- a/src/inputs/mod.rs +++ b/src/inputs/mod.rs @@ -5,15 +5,17 @@ use std::fs::File; use std::io::Write; use std::io::Read; +use crate::AflError; + pub trait Input { - fn to_file(&self, path: &str) -> Result<(), Error> { + fn to_file(&self, path: &str) -> Result<(), AflError> { let mut file = File::create(path)?; file.write_all(self.serialize()?)?; Ok(()) } - fn from_file(&mut self, path: &str) -> Result<(), Error> { + fn from_file(&mut self, path: &str) -> Result<(), AflError> { let mut file = File::create(path)?; let mut buf = vec![]; file.read_to_end(&mut buf)?; @@ -21,8 +23,8 @@ pub trait Input { Ok(()) } - fn serialize(&self) -> Result<&[u8], Error>; + fn serialize(&self) -> Result<&[u8], AflError>; - fn deserialize(&mut self, buf: &[u8]) -> Result<(), Error>; + fn deserialize(&mut self, buf: &[u8]) -> Result<(), AflError>; } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 11e96aff18..dcea1eeb23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,7 @@ +use std::io; +use thiserror::Error; + +pub mod corpus; pub mod engines; pub mod executors; pub mod feedbacks; @@ -7,6 +11,19 @@ pub mod mutators; pub mod stages; pub mod utils; +#[derive(Error, Debug)] +pub enum AflError { + #[error("Error in Serialization: `{0}`")] + Serialize(String), + #[error("File IO failed")] + File(#[from] io::Error), + #[error("Key `{0}` not in Corpus")] + KeyNotFound(String), + #[error("Unknown error")] + Unknown, +} + + #[cfg(test)] mod tests { #[test] diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index e50d703d48..0000000000 --- a/src/main.rs +++ /dev/null @@ -1,12 +0,0 @@ -pub mod engines; -pub mod executors; -pub mod feedbacks; -pub mod inputs; -pub mod monitors; -pub mod mutators; -pub mod stages; -pub mod utils; - -fn main() { - println!("Hello, world!"); -}