diff --git a/pkstrings/src/pkstring.rs b/pkstrings/src/pkstring.rs index 82b6a48..f466e4f 100644 --- a/pkstrings/src/pkstring.rs +++ b/pkstrings/src/pkstring.rs @@ -88,13 +88,15 @@ const fn hextostr(hex: u8) -> Option { #[derive(Debug, Eq, PartialEq)] pub enum Error { - InvalidCharacter, + InvalidByte(u8), + InvalidCharacter(char), } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { match self { - Error::InvalidCharacter => write!(f, "Invalid character"), + Error::InvalidByte(ord) => write!(f, "Invalid byte: {:?}", ord), + Error::InvalidCharacter(chr) => write!(f, "Invalid character: {:?}", chr), } } } @@ -124,7 +126,7 @@ impl TryFrom for PKString { match hextostr(ord) { Some(chr) => buf.push(chr.clone()), - None => return Err(Error::InvalidCharacter), + None => return Err(Error::InvalidByte(ord)), } Ok(PKString(buf)) @@ -140,7 +142,7 @@ impl TryFrom<&[u8]> for PKString { for ord in data { match hextostr(*ord) { Some(chr) => buf.push(chr.clone()), - None => return Err(Error::InvalidCharacter), + None => return Err(Error::InvalidByte(*ord)), } } @@ -170,7 +172,7 @@ impl TryFrom for PKString { fn try_from(data: String) -> Result { for chr in data.chars() { if strtohex(&chr).is_none() { - return Err(Error::InvalidCharacter); + return Err(Error::InvalidCharacter(chr)); } }