chore(boring): simplify extensions sort order calculation (#58)

This commit is contained in:
0x676e67 2025-03-20 23:15:54 +08:00 committed by GitHub
parent d3911bfc86
commit 94cd4e1498
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 28 deletions

View File

@ -609,35 +609,16 @@ impl ExtensionType {
/// Returns the index of the given extension type in the permutation. /// Returns the index of the given extension type in the permutation.
pub const fn index_of(value: ExtensionType) -> Option<usize> { pub const fn index_of(value: ExtensionType) -> Option<usize> {
match value { let mut i = 0;
ExtensionType::SERVER_NAME => Some(0), while i < Self::BORING_SSLEXTENSION_PERMUTATION.len() {
ExtensionType::ENCRYPTED_CLIENT_HELLO => Some(1), if i < Self::BORING_SSLEXTENSION_PERMUTATION.len()
ExtensionType::EXTENDED_MASTER_SECRET => Some(2), && Self::BORING_SSLEXTENSION_PERMUTATION[i].0 == value.0
ExtensionType::RENEGOTIATE => Some(3), {
ExtensionType::SUPPORTED_GROUPS => Some(4), return Some(i);
ExtensionType::EC_POINT_FORMATS => Some(5),
ExtensionType::SESSION_TICKET => Some(6),
ExtensionType::APPLICATION_LAYER_PROTOCOL_NEGOTIATION => Some(7),
ExtensionType::STATUS_REQUEST => Some(8),
ExtensionType::SIGNATURE_ALGORITHMS => Some(9),
ExtensionType::NEXT_PROTO_NEG => Some(10),
ExtensionType::CERTIFICATE_TIMESTAMP => Some(11),
ExtensionType::CHANNEL_ID => Some(12),
ExtensionType::SRTP => Some(13),
ExtensionType::KEY_SHARE => Some(14),
ExtensionType::PSK_KEY_EXCHANGE_MODES => Some(15),
ExtensionType::EARLY_DATA => Some(16),
ExtensionType::SUPPORTED_VERSIONS => Some(17),
ExtensionType::COOKIE => Some(18),
ExtensionType::QUIC_TRANSPORT_PARAMETERS_STANDARD => Some(19),
ExtensionType::QUIC_TRANSPORT_PARAMETERS_LEGACY => Some(20),
ExtensionType::CERT_COMPRESSION => Some(21),
ExtensionType::DELEGATED_CREDENTIAL => Some(22),
ExtensionType::APPLICATION_SETTINGS => Some(23),
ExtensionType::APPLICATION_SETTINGS_NEW => Some(24),
ExtensionType::RECORD_SIZE_LIMIT => Some(25),
_ => None,
} }
i += 1;
}
None
} }
} }

View File

@ -0,0 +1,10 @@
use crate::ssl::ExtensionType;
#[test]
fn test_exntension_order_index() {
let mut i = 0;
for ext in ExtensionType::BORING_SSLEXTENSION_PERMUTATION {
assert_eq!(ExtensionType::index_of(*ext), Some(i));
i += 1;
}
}

View File

@ -28,6 +28,7 @@ mod cert_verify;
mod custom_verify; mod custom_verify;
#[cfg(not(feature = "fips"))] #[cfg(not(feature = "fips"))]
mod ech; mod ech;
mod extensions;
mod private_key_method; mod private_key_method;
mod server; mod server;
mod session; mod session;