error.rs (2865B)
1 #[cfg(doc)] 2 use super::{ 3 AuthenticatorSelectionCriteria, CredProtect, CredentialCreationOptions, Extension, Nickname, 4 PublicKeyCredentialCreationOptions, USER_HANDLE_MAX_LEN, USER_HANDLE_MIN_LEN, UserHandle, 5 UserVerificationRequirement, Username, 6 }; 7 use core::{ 8 error::Error, 9 fmt::{self, Display, Formatter}, 10 }; 11 #[cfg(doc)] 12 use std::time::{Instant, SystemTime}; 13 /// Error returned by [`Nickname::try_from`]. 14 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 15 pub enum NicknameErr { 16 /// Error returned when the [Nickname Enforcement rule](https://www.rfc-editor.org/rfc/rfc8266#section-2.3) 17 /// fails. 18 Rfc8266, 19 /// Error returned when the length of the transformed string would exceed [`Nickname::MAX_LEN`] or 20 /// [`Nickname::RECOMMENDED_MAX_LEN`]. 21 Len, 22 } 23 impl Display for NicknameErr { 24 #[inline] 25 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { 26 f.write_str(match *self { 27 Self::Rfc8266 => "nickname does not conform to RFC 8266", 28 Self::Len => "length of nickname is too long", 29 }) 30 } 31 } 32 impl Error for NicknameErr {} 33 /// Error returned by [`Username::try_from`]. 34 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 35 pub enum UsernameErr { 36 /// Error returned when the 37 /// [UsernameCasePreserved Enforcement rule](https://www.rfc-editor.org/rfc/rfc8265#section-3.4.3) fails. 38 Rfc8265, 39 /// Error returned when the length of the transformed string would exceed [`Username::MAX_LEN`] or 40 /// [`Username::RECOMMENDED_MAX_LEN`]. 41 Len, 42 } 43 impl Display for UsernameErr { 44 #[inline] 45 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { 46 f.write_str(match *self { 47 Self::Rfc8265 => "username does not conform to RFC 8265", 48 Self::Len => "length of username is too long", 49 }) 50 } 51 } 52 impl Error for UsernameErr {} 53 /// Error returned by [`CredentialCreationOptions::start_ceremony`]. 54 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 55 pub enum CreationOptionsErr { 56 /// Error when [`Extension::cred_protect`] is [`CredProtect::UserVerificationRequired`] but [`AuthenticatorSelectionCriteria::user_verification`] is not 57 /// [`UserVerificationRequirement::Required`]. 58 CredProtectRequiredWithoutUserVerification, 59 /// [`PublicKeyCredentialCreationOptions::timeout`] could not be added to [`Instant::now`] or [`SystemTime::now`]. 60 InvalidTimeout, 61 } 62 impl Display for CreationOptionsErr { 63 #[inline] 64 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { 65 f.write_str(match *self { 66 Self::CredProtectRequiredWithoutUserVerification => "credProtect extension with a value of user verification required was requested without requiring user verification", 67 Self::InvalidTimeout => "the timeout could not be added to the current Instant", 68 }) 69 } 70 } 71 impl Error for CreationOptionsErr {}