@@ -11,8 +11,8 @@ use crate::log::MaybeFancy;
11
11
12
12
pub struct CreateKeyCmd {
13
13
pub cryptoki_config : CryptokiConfig ,
14
- pub bits : u16 ,
15
- pub curve : u16 ,
14
+ pub bits : RsaBits ,
15
+ pub curve : EcCurve ,
16
16
pub label : String ,
17
17
pub r#type : KeyType ,
18
18
/// The device identifier to be used as the common name for the certificate
@@ -27,6 +27,41 @@ pub enum KeyType {
27
27
Ec ,
28
28
}
29
29
30
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , ValueEnum ) ]
31
+ pub enum RsaBits {
32
+ #[ value( name = "2048" ) ]
33
+ Bits2048 ,
34
+ #[ value( name = "3072" ) ]
35
+ Bits3072 ,
36
+ #[ value( name = "4096" ) ]
37
+ Bits4096 ,
38
+ }
39
+
40
+ impl From < RsaBits > for u16 {
41
+ fn from ( value : RsaBits ) -> Self {
42
+ match value {
43
+ RsaBits :: Bits2048 => 2048 ,
44
+ RsaBits :: Bits3072 => 3072 ,
45
+ RsaBits :: Bits4096 => 4096 ,
46
+ }
47
+ }
48
+ }
49
+
50
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , ValueEnum ) ]
51
+ pub enum EcCurve {
52
+ P256 ,
53
+ P384 ,
54
+ }
55
+
56
+ impl From < EcCurve > for u16 {
57
+ fn from ( value : EcCurve ) -> Self {
58
+ match value {
59
+ EcCurve :: P256 => 256 ,
60
+ EcCurve :: P384 => 384 ,
61
+ }
62
+ }
63
+ }
64
+
30
65
#[ async_trait:: async_trait]
31
66
impl Command for CreateKeyCmd {
32
67
fn description ( & self ) -> String {
@@ -35,8 +70,12 @@ impl Command for CreateKeyCmd {
35
70
36
71
async fn execute ( & self , _config : TEdgeConfig ) -> Result < ( ) , MaybeFancy < anyhow:: Error > > {
37
72
let key = match self . r#type {
38
- KeyType :: Rsa => KeyTypeParams :: Rsa { bits : self . bits } ,
39
- KeyType :: Ec => KeyTypeParams :: Ec { curve : self . curve } ,
73
+ KeyType :: Rsa => KeyTypeParams :: Rsa {
74
+ bits : self . bits . into ( ) ,
75
+ } ,
76
+ KeyType :: Ec => KeyTypeParams :: Ec {
77
+ curve : self . curve . into ( ) ,
78
+ } ,
40
79
} ;
41
80
let params = CreateKeyParams {
42
81
key,
@@ -54,13 +93,8 @@ impl Command for CreateKeyCmd {
54
93
// use returned public key to create a CSR
55
94
let sigalg = match ( self . r#type , self . curve ) {
56
95
( KeyType :: Rsa , _) => certificate:: SignatureAlgorithm :: RsaPkcs1Sha256 ,
57
- ( KeyType :: Ec , 256 ) => certificate:: SignatureAlgorithm :: EcdsaP256Sha256 ,
58
- ( KeyType :: Ec , 384 ) => certificate:: SignatureAlgorithm :: EcdsaP384Sha384 ,
59
- _ => {
60
- return Err (
61
- anyhow:: anyhow!( "invalid arguments: bad keytype/arg combination" ) . into ( ) ,
62
- )
63
- }
96
+ ( KeyType :: Ec , EcCurve :: P256 ) => certificate:: SignatureAlgorithm :: EcdsaP256Sha256 ,
97
+ ( KeyType :: Ec , EcCurve :: P384 ) => certificate:: SignatureAlgorithm :: EcdsaP384Sha384 ,
64
98
} ;
65
99
66
100
let key = super :: create_csr:: Key :: Cryptoki {
0 commit comments