-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from danielpclark/error_system
Error system
- Loading branch information
Showing
8 changed files
with
179 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "abrute" | ||
version = "0.0.6" | ||
version = "0.1.0" | ||
authors = ["Daniel P. Clark <[email protected]>"] | ||
description = "AESCrypt Brute force attempter." | ||
documentation = "http:https://danielpclark.github.io/abrute/index.html" | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use std::fmt; | ||
use std::error::Error as StdError; | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
AescryptMissing, | ||
FileMissing, | ||
InvalidAdjacentNumber, | ||
InvalidCharacterSet, | ||
InvalidRange, | ||
InvalidStringLength, | ||
PasswordNotFound, | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match *self { | ||
Error::AescryptMissing => f.write_str("AescryptMissing" ), | ||
Error::FileMissing => f.write_str("FileMissing" ), | ||
Error::InvalidAdjacentNumber => f.write_str("InvalidAdjacentNumber"), | ||
Error::InvalidCharacterSet => f.write_str("InvalidCharacterSet" ), | ||
Error::InvalidRange => f.write_str("InvalidRange" ), | ||
Error::InvalidStringLength => f.write_str("InvalidStringLength" ), | ||
Error::PasswordNotFound => f.write_str("PasswordNotFound" ), | ||
} | ||
} | ||
} | ||
|
||
#[inline] | ||
fn aescrypt_missing() -> &'static str { | ||
"aescrypt does not appear to be installed." | ||
} | ||
|
||
#[inline] | ||
fn file_missing() -> &'static str { | ||
"The target file seems to be missing." | ||
} | ||
|
||
#[inline] | ||
fn invalid_adjacent_number() -> &'static str { | ||
"Invalid number for adjacent input." | ||
} | ||
|
||
#[inline] | ||
fn invalid_character_set() -> &'static str { | ||
"Invalid character set provided for start." | ||
} | ||
|
||
#[inline] | ||
fn invalid_range() -> &'static str { | ||
"Invalid range input given." | ||
} | ||
|
||
#[inline] | ||
fn invalid_string_length() -> &'static str { | ||
"Invalid string length for start given." | ||
} | ||
|
||
#[inline] | ||
fn password_not_found() -> &'static str { | ||
"Password not found for given length and character set." | ||
} | ||
|
||
impl StdError for Error { | ||
fn description(&self) -> &str { | ||
match *self { | ||
Error::AescryptMissing => aescrypt_missing(), | ||
Error::FileMissing => file_missing(), | ||
Error::InvalidAdjacentNumber => invalid_adjacent_number(), | ||
Error::InvalidCharacterSet => invalid_character_set(), | ||
Error::InvalidRange => invalid_range(), | ||
Error::InvalidStringLength => invalid_string_length(), | ||
Error::PasswordNotFound => password_not_found(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
pub fn validate_is_digit(v: String) -> Result<(), String> { | ||
use super::result::Error; | ||
|
||
pub fn validate_adjacent_input(v: String) -> Result<(), Error> { | ||
if v.parse::<u8>().is_ok() { return Ok(()); } | ||
Err(String::from("The value did not contain valid digit from 0 to 255")) | ||
Err(Error::InvalidAdjacentNumber) | ||
} | ||
|
||
pub fn validate_string_length(v: &str, max: usize) -> Result<(), String> { | ||
pub fn validate_string_length(v: &str, max: usize) -> Result<(), Error> { | ||
if v.len() <= max { return Ok(()); } | ||
Err(String::from("The value did not contain valid digit from 0 to 255")) | ||
Err(Error::InvalidStringLength) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters