@@ -16,8 +16,18 @@ use crate::util::attribute::{AttrData, AttributeMap, AttributeType};
1616use crate :: util:: helper;
1717use crate :: util:: signing:: MlDsaDomain ;
1818
19- fn default_mldsa_type ( ) -> String {
20- "87" . to_string ( )
19+ #[ derive( clap:: ValueEnum , Debug , Clone , Copy , PartialEq , Eq , Serialize , Deserialize , Default ) ]
20+ pub enum MlDsaType {
21+ #[ serde( rename = "44" ) ]
22+ #[ value( name = "44" ) ]
23+ MlDsa44 = 1 ,
24+ #[ serde( rename = "65" ) ]
25+ #[ value( name = "65" ) ]
26+ MlDsa65 = 2 ,
27+ #[ default]
28+ #[ serde( rename = "87" ) ]
29+ #[ value( name = "87" ) ]
30+ MlDsa87 = 3 ,
2131}
2232
2333#[ derive( clap:: Args , Debug , Serialize , Deserialize ) ]
@@ -31,10 +41,10 @@ pub struct Generate {
3141 /// Permit the generated key to be extractable.
3242 #[ arg( long) ]
3343 extractable : bool ,
34- /// MLDSA algorithm type.
35- #[ arg( long, default_value = "87" , value_parser = [ "44" , "65" , "87" ] ) ]
36- #[ serde( default = "default_mldsa_type" ) ]
37- mldsa_type : String ,
44+ /// MLDSA algorithm type for the key .
45+ #[ arg( long, value_enum , default_value_t = MlDsaType :: MlDsa87 ) ]
46+ #[ serde( default ) ]
47+ mldsa_type : MlDsaType ,
3848 /// The ML-DSA domain.
3949 #[ arg( long, value_enum, default_value_t = MlDsaDomain :: Pure ) ]
4050 domain : MlDsaDomain ,
@@ -90,16 +100,9 @@ impl Dispatch for Generate {
90100 public_template. insert ( AttributeType :: Id , id. clone ( ) ) ;
91101 public_template. insert ( AttributeType :: Label , result. label . clone ( ) ) ;
92102
93- let mldsa_type_val = match self . mldsa_type . as_str ( ) {
94- "44" => 1 ,
95- "65" => 2 ,
96- "87" => 3 ,
97- _ => unreachable ! ( ) ,
98- } ;
99-
100103 public_template. insert (
101104 AttributeType :: ParameterSet ,
102- AttrData :: from ( mldsa_type_val ) ,
105+ AttrData :: from ( self . mldsa_type as u64 ) ,
103106 ) ;
104107
105108 if let Some ( tpl) = & self . public_template {
0 commit comments