@@ -146,11 +146,11 @@ impl Key {
146
146
/// Valid keys can only contain 32 chars including 0-9, a-z and A-Z.
147
147
pub fn new ( value : & str ) -> Result < Self , ParseKeyError > {
148
148
if value. len ( ) != AUTH_KEY_LENGTH {
149
- return Err ( ParseKeyError ) ;
149
+ return Err ( ParseKeyError :: InvalidKeyLength ) ;
150
150
}
151
151
152
152
if !value. chars ( ) . all ( |c| c. is_ascii_alphanumeric ( ) ) {
153
- return Err ( ParseKeyError ) ;
153
+ return Err ( ParseKeyError :: InvalidChars ) ;
154
154
}
155
155
156
156
Ok ( Self ( value. to_owned ( ) ) )
@@ -175,9 +175,15 @@ impl Key {
175
175
/// assert_eq!(key.unwrap().to_string(), key_string);
176
176
/// ```
177
177
///
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
+ }
181
187
182
188
impl FromStr for Key {
183
189
type Err = ParseKeyError ;
@@ -188,8 +194,8 @@ impl FromStr for Key {
188
194
}
189
195
}
190
196
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.
193
199
#[ derive( Debug , Error ) ]
194
200
#[ allow( dead_code) ]
195
201
pub enum Error {
0 commit comments