@ -2,6 +2,9 @@
//! possible in CBOR format while maintaining ergonomic enum variants for public
//! possible in CBOR format while maintaining ergonomic enum variants for public
//! API.
//! API.
use super ::Permission ;
use flagset ::flags ;
use flagset ::FlagSet ;
use serde ::{ Deserialize , Serialize } ;
use serde ::{ Deserialize , Serialize } ;
mod public_key ;
mod public_key ;
@ -24,3 +27,52 @@ impl From<RawSubcommand> for u8 {
}
}
}
}
flags ! {
#[ derive(Serialize, Deserialize) ]
pub enum RawPermission : u8 {
MakeCredential = 0x01 ,
GetAssertion = 0x02 ,
CredentialManagement = 0x04 ,
BioEnrollment = 0x08 ,
LargeBlobWrite = 0x10 ,
AuthenticatorConfiguration = 0x20 ,
}
}
impl From < Permission > for RawPermission {
fn from ( value : Permission ) -> Self {
match value {
Permission ::MakeCredential = > Self ::MakeCredential ,
Permission ::GetAssertion = > Self ::GetAssertion ,
Permission ::CredentialManagement = > Self ::CredentialManagement ,
Permission ::BiometricEnrollment = > Self ::BioEnrollment ,
Permission ::LargeBlobWrite = > Self ::LargeBlobWrite ,
Permission ::AuthenticatorConfiguration = > Self ::AuthenticatorConfiguration ,
}
}
}
impl From < RawPermission > for Permission {
fn from ( value : RawPermission ) -> Self {
match value {
RawPermission ::MakeCredential = > Self ::MakeCredential ,
RawPermission ::GetAssertion = > Self ::GetAssertion ,
RawPermission ::CredentialManagement = > Self ::CredentialManagement ,
RawPermission ::BioEnrollment = > Self ::BiometricEnrollment ,
RawPermission ::LargeBlobWrite = > Self ::LargeBlobWrite ,
RawPermission ::AuthenticatorConfiguration = > Self ::AuthenticatorConfiguration ,
}
}
}
impl FromIterator < Permission > for FlagSet < RawPermission > {
fn from_iter < T : IntoIterator < Item = Permission > > ( iter : T ) -> Self {
iter . into_iter ( )
. map ( RawPermission ::from )
. fold ( None . into ( ) , | mut set , flag | {
set | = flag ;
set
} )
}
}