@@ -10,39 +10,56 @@ use crate::{
10
10
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
11
11
pub enum NamedGroup {
12
12
/* Elliptic Curve Groups (ECDHE) */
13
- Secp256r1 = 0x0017 ,
14
- Secp384r1 = 0x0018 ,
15
- Secp521r1 = 0x0019 ,
16
- X25519 = 0x001D ,
17
- X448 = 0x001E ,
13
+ Secp256r1 ,
14
+ Secp384r1 ,
15
+ Secp521r1 ,
16
+ X25519 ,
17
+ X448 ,
18
18
19
19
/* Finite Field Groups (DHE) */
20
- Ffdhe2048 = 0x0100 ,
21
- Ffdhe3072 = 0x0101 ,
22
- Ffdhe4096 = 0x0102 ,
23
- Ffdhe6144 = 0x0103 ,
24
- Ffdhe8192 = 0x0104 ,
20
+ Ffdhe2048 ,
21
+ Ffdhe3072 ,
22
+ Ffdhe4096 ,
23
+ Ffdhe6144 ,
24
+ Ffdhe8192 ,
25
25
}
26
26
27
27
impl NamedGroup {
28
28
pub fn parse ( buf : & mut ParseBuffer ) -> Result < Self , ParseError > {
29
29
match buf. read_u16 ( ) ? {
30
- v if v == Self :: Secp256r1 as u16 => Ok ( Self :: Secp256r1 ) ,
31
- v if v == Self :: Secp384r1 as u16 => Ok ( Self :: Secp384r1 ) ,
32
- v if v == Self :: Secp521r1 as u16 => Ok ( Self :: Secp521r1 ) ,
33
- v if v == Self :: X25519 as u16 => Ok ( Self :: X25519 ) ,
34
- v if v == Self :: X448 as u16 => Ok ( Self :: X448 ) ,
35
- v if v == Self :: Ffdhe2048 as u16 => Ok ( Self :: Ffdhe2048 ) ,
36
- v if v == Self :: Ffdhe3072 as u16 => Ok ( Self :: Ffdhe3072 ) ,
37
- v if v == Self :: Ffdhe4096 as u16 => Ok ( Self :: Ffdhe4096 ) ,
38
- v if v == Self :: Ffdhe6144 as u16 => Ok ( Self :: Ffdhe6144 ) ,
39
- v if v == Self :: Ffdhe8192 as u16 => Ok ( Self :: Ffdhe8192 ) ,
30
+ 0x0017 => Ok ( Self :: Secp256r1 ) ,
31
+ 0x0018 => Ok ( Self :: Secp384r1 ) ,
32
+ 0x0019 => Ok ( Self :: Secp521r1 ) ,
33
+ 0x001D => Ok ( Self :: X25519 ) ,
34
+ 0x001E => Ok ( Self :: X448 ) ,
35
+
36
+ 0x0100 => Ok ( Self :: Ffdhe2048 ) ,
37
+ 0x0101 => Ok ( Self :: Ffdhe3072 ) ,
38
+ 0x0102 => Ok ( Self :: Ffdhe4096 ) ,
39
+ 0x0103 => Ok ( Self :: Ffdhe6144 ) ,
40
+ 0x0104 => Ok ( Self :: Ffdhe8192 ) ,
40
41
_ => Err ( ParseError :: InvalidData ) ,
41
42
}
42
43
}
43
44
45
+ pub fn as_u16 ( self ) -> u16 {
46
+ match self {
47
+ Self :: Secp256r1 => 0x0017 ,
48
+ Self :: Secp384r1 => 0x0018 ,
49
+ Self :: Secp521r1 => 0x0019 ,
50
+ Self :: X25519 => 0x001D ,
51
+ Self :: X448 => 0x001E ,
52
+
53
+ Self :: Ffdhe2048 => 0x0100 ,
54
+ Self :: Ffdhe3072 => 0x0101 ,
55
+ Self :: Ffdhe4096 => 0x0102 ,
56
+ Self :: Ffdhe6144 => 0x0103 ,
57
+ Self :: Ffdhe8192 => 0x0104 ,
58
+ }
59
+ }
60
+
44
61
pub fn encode ( & self , buf : & mut CryptoBuffer ) -> Result < ( ) , TlsError > {
45
- buf. push_u16 ( * self as u16 )
62
+ buf. push_u16 ( self . as_u16 ( ) )
46
63
. map_err ( |_| TlsError :: EncodeError )
47
64
}
48
65
}
0 commit comments