hickory_proto/rr/dnssec/
key_format.rs#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum KeyFormat {
Der,
Pem,
Pkcs8,
}
#[cfg(test)]
mod tests {
#![allow(clippy::dbg_macro, clippy::print_stdout)]
use super::*;
use crate::rr::dnssec::keypair::decode_key;
use crate::rr::dnssec::Algorithm;
#[cfg(feature = "dnssec-openssl")]
use crate::rr::dnssec::{EcSigningKey, RsaSigningKey};
#[cfg(feature = "dnssec-ring")]
use crate::rr::dnssec::{EcdsaSigningKey, Ed25519SigningKey};
#[test]
#[cfg(feature = "dnssec-openssl")]
fn test_rsa_encode_decode_der() {
let algorithm = Algorithm::RSASHA256;
let key = RsaSigningKey::generate(algorithm).unwrap();
let der = key.encode_der().unwrap();
decode_key(&der, None, algorithm, KeyFormat::Der).unwrap();
}
#[test]
#[cfg(feature = "dnssec-openssl")]
fn test_rsa_encode_decode_pem() {
let algorithm = Algorithm::RSASHA256;
let key = RsaSigningKey::generate(algorithm).unwrap();
let pem = key.encode_pem(None).unwrap();
decode_key(&pem, None, algorithm, KeyFormat::Pem).unwrap();
let encrypted = key.encode_pem(Some("test password")).unwrap();
decode_key(&encrypted, Some("test password"), algorithm, KeyFormat::Pem).unwrap();
}
#[test]
#[cfg(feature = "dnssec-openssl")]
fn test_ec_encode_decode_der() {
let algorithm = Algorithm::ECDSAP256SHA256;
let key = EcSigningKey::generate(algorithm).unwrap();
let der = key.encode_der().unwrap();
decode_key(&der, None, algorithm, KeyFormat::Der).unwrap();
}
#[test]
#[cfg(feature = "dnssec-openssl")]
fn test_ec_encode_decode_pem() {
let algorithm = Algorithm::ECDSAP256SHA256;
let key = EcSigningKey::generate(algorithm).unwrap();
let pem = key.encode_pem(None).unwrap();
decode_key(&pem, None, algorithm, KeyFormat::Pem).unwrap();
let encrypted = key.encode_pem(Some("test password")).unwrap();
decode_key(&encrypted, Some("test password"), algorithm, KeyFormat::Pem).unwrap();
}
#[test]
#[cfg(feature = "dnssec-ring")]
fn test_ec_encode_decode_pkcs8() {
let algorithm = Algorithm::ECDSAP256SHA256;
let pkcs8 = EcdsaSigningKey::generate_pkcs8(algorithm).unwrap();
decode_key(&pkcs8, None, algorithm, KeyFormat::Pkcs8).unwrap();
}
#[test]
#[cfg(feature = "dnssec-ring")]
fn test_ed25519_encode_decode_pkcs8() {
let pkcs8 = Ed25519SigningKey::generate_pkcs8().unwrap();
decode_key(&pkcs8, None, Algorithm::ED25519, KeyFormat::Pkcs8).unwrap();
}
}