nethsm::key

Function tls_key_type_matches_length

source
pub fn tls_key_type_matches_length(
    tls_key_type: TlsKeyType,
    length: Option<u32>,
) -> Result<(), Error>
Expand description

Ensures that a TlsKeyType is compatible with an optional key length

§Errors

Returns an Error::Key if

§Examples

use nethsm::{tls_key_type_matches_length, TlsKeyType};

tls_key_type_matches_length(TlsKeyType::Curve25519, None)?;
tls_key_type_matches_length(TlsKeyType::EcP224, None)?;
tls_key_type_matches_length(TlsKeyType::Rsa, Some(2048))?;

// this fails because elliptic curve keys have their length set intrinsically
assert!(tls_key_type_matches_length(TlsKeyType::Curve25519, Some(2048)).is_err());
// this fails because a bit length of 1024 is unsafe to use for RSA keys
assert!(tls_key_type_matches_length(TlsKeyType::Rsa, Some(1024)).is_err());