MCPcopy Index your code
hub / github.com/RustPython/RustPython / curve_name_to_kx_group

Function curve_name_to_kx_group

crates/stdlib/src/ssl/compat.rs:2364–2409  ·  view source on GitHub ↗

Convert curve name to rustls key exchange group Maps OpenSSL curve names (e.g., "prime256v1", "secp384r1") to rustls KxGroups. Returns an error if the curve is not supported by rustls.

(
    curve: &str,
)

Source from the content-addressed store, hash-verified

2362/// Maps OpenSSL curve names (e.g., "prime256v1", "secp384r1") to rustls KxGroups.
2363/// Returns an error if the curve is not supported by rustls.
2364pub(super) fn curve_name_to_kx_group(
2365 curve: &str,
2366) -> Result<Vec<&'static dyn SupportedKxGroup>, String> {
2367 // Get the default crypto provider's key exchange groups
2368 let provider = rustls::crypto::aws_lc_rs::default_provider();
2369 let all_groups = &provider.kx_groups;
2370
2371 match curve {
2372 // P-256 (also known as secp256r1 or prime256v1)
2373 "prime256v1" | "secp256r1" => {
2374 // Find SECP256R1 in the provider's groups
2375 all_groups
2376 .iter()
2377 .find(|g| g.name() == rustls::NamedGroup::secp256r1)
2378 .map(|g| vec![*g])
2379 .ok_or_else(|| "secp256r1 not supported by crypto provider".to_owned())
2380 }
2381 // P-384 (also known as secp384r1 or prime384v1)
2382 "secp384r1" | "prime384v1" => all_groups
2383 .iter()
2384 .find(|g| g.name() == rustls::NamedGroup::secp384r1)
2385 .map(|g| vec![*g])
2386 .ok_or_else(|| "secp384r1 not supported by crypto provider".to_owned()),
2387 // X25519
2388 "X25519" | "x25519" => all_groups
2389 .iter()
2390 .find(|g| g.name() == rustls::NamedGroup::X25519)
2391 .map(|g| vec![*g])
2392 .ok_or_else(|| "X25519 not supported by crypto provider".to_owned()),
2393 // P-521 (also known as secp521r1 or prime521v1)
2394 // Now supported with aws-lc-rs crypto provider
2395 "prime521v1" | "secp521r1" => all_groups
2396 .iter()
2397 .find(|g| g.name() == rustls::NamedGroup::secp521r1)
2398 .map(|g| vec![*g])
2399 .ok_or_else(|| "secp521r1 not supported by crypto provider".to_owned()),
2400 // X448
2401 // Now supported with aws-lc-rs crypto provider
2402 "X448" | "x448" => all_groups
2403 .iter()
2404 .find(|g| g.name() == rustls::NamedGroup::X448)
2405 .map(|g| vec![*g])
2406 .ok_or_else(|| "X448 not supported by crypto provider".to_owned()),
2407 _ => Err(format!("unknown curve name '{curve}'")),
2408 }
2409}

Callers 1

prepare_kx_groupsMethod · 0.85

Calls 7

ok_or_elseMethod · 0.80
ErrClass · 0.50
mapMethod · 0.45
findMethod · 0.45
iterMethod · 0.45
nameMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected