nethsm::key

Function key_type_matches_length

source
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::Key if

§Examples

use nethsm::{key_type_matches_length, KeyType};

key_type_matches_length(KeyType::Curve25519, None)?;
key_type_matches_length(KeyType::EcP224, 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());