Function key_type_matches_length
pub fn key_type_matches_length(
key_type: KeyType,
length: Option<u32>,
) -> Result<(), Error>Expand description
Ensures that a KeyType is compatible with an optional key length
§Errors
Returns an error if
key_typeis one ofKeyType::Curve25519,KeyType::EcP256,KeyType::EcP384orKeyType::EcP521andlengthisSome.key_typeisKeyType::GenericorKeyType::RsaandlengthisNone.key_typeisKeyType::Genericandlengthis notSomevalue of128,192or256.key_typeisKeyType::Rsaandlengthis notSomevalue equal to or greater than [MIN_RSA_BIT_LENGTH].
§Examples
use signstar_crypto::key::{KeyType, key_type_matches_length};
key_type_matches_length(KeyType::Curve25519, None)?;
key_type_matches_length(KeyType::EcP256, None)?;
key_type_matches_length(KeyType::Rsa, Some(2048))?;
key_type_matches_length(KeyType::Generic, Some(256))?;
// this fails because elliptic curve keys have their length set intrinsically
assert!(key_type_matches_length(KeyType::Curve25519, Some(2048)).is_err());
// this fails because a bit length of 2048 is not defined for AES block ciphers
assert!(key_type_matches_length(KeyType::Generic, Some(2048)).is_err());
// this fails because a bit length of 1024 is unsafe to use for RSA keys
assert!(key_type_matches_length(KeyType::Rsa, Some(1024)).is_err());