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
tls_key_type
is one ofTlsKeyType::Curve25519
,TlsKeyType::EcP224
,TlsKeyType::EcP256
,TlsKeyType::EcP384
orTlsKeyType::EcP521
andlength
isSome
.tls_key_type
isTlsKeyType::Rsa
andlength
isNone
.tls_key_type
isTlsKeyType::Rsa
andlength
is notSome
value equal to or greater thanMIN_RSA_BIT_LENGTH
.
§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());