@@ -146,11 +146,11 @@ impl Key {
146146 /// Valid keys can only contain 32 chars including 0-9, a-z and A-Z.
147147 pub fn new ( value : & str ) -> Result < Self , ParseKeyError > {
148148 if value. len ( ) != AUTH_KEY_LENGTH {
149- return Err ( ParseKeyError ) ;
149+ return Err ( ParseKeyError :: InvalidKeyLength ) ;
150150 }
151151
152152 if !value. chars ( ) . all ( |c| c. is_ascii_alphanumeric ( ) ) {
153- return Err ( ParseKeyError ) ;
153+ return Err ( ParseKeyError :: InvalidChars ) ;
154154 }
155155
156156 Ok ( Self ( value. to_owned ( ) ) )
@@ -175,9 +175,15 @@ impl Key {
175175/// assert_eq!(key.unwrap().to_string(), key_string);
176176/// ```
177177///
178- /// If the string does not contains a valid key, the parser function will return this error.
179- #[ derive( Debug , PartialEq , Eq , Display ) ]
180- pub struct ParseKeyError ;
178+ /// If the string does not contains a valid key, the parser function will return
179+ /// this error.
180+ #[ derive( Debug , Error ) ]
181+ pub enum ParseKeyError {
182+ #[ error( "Invalid key length. Key must be have 32 chars" ) ]
183+ InvalidKeyLength ,
184+ #[ error( "Invalid chars for key. Key can only alphanumeric chars (0-9, a-z, A-Z)" ) ]
185+ InvalidChars ,
186+ }
181187
182188impl FromStr for Key {
183189 type Err = ParseKeyError ;
@@ -188,8 +194,8 @@ impl FromStr for Key {
188194 }
189195}
190196
191- /// Verification error. Error returned when an [`ExpiringKey`] cannot be verified with the [`verify(...)`](crate::core::auth::verify) function.
192- ///
197+ /// Verification error. Error returned when an [`ExpiringKey`] cannot be
198+ /// verified with the [`verify(...)`](crate::core::auth::verify) function.
193199#[ derive( Debug , Error ) ]
194200#[ allow( dead_code) ]
195201pub enum Error {
0 commit comments