Skip to content

Commit a49a8a7

Browse files
committed
Shrink the size of ServerHandshake::EncryptedExtensions
1 parent 9de49c2 commit a49a8a7

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

src/extensions/extension_data/supported_groups.rs

+38-21
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,56 @@ use crate::{
1010
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1111
pub enum NamedGroup {
1212
/* 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,
1818

1919
/* 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,
2525
}
2626

2727
impl NamedGroup {
2828
pub fn parse(buf: &mut ParseBuffer) -> Result<Self, ParseError> {
2929
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),
4041
_ => Err(ParseError::InvalidData),
4142
}
4243
}
4344

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+
4461
pub fn encode(&self, buf: &mut CryptoBuffer) -> Result<(), TlsError> {
45-
buf.push_u16(*self as u16)
62+
buf.push_u16(self.as_u16())
4663
.map_err(|_| TlsError::EncodeError)
4764
}
4865
}

0 commit comments

Comments
 (0)