use super::algorithms::{Algorithm, DnskeyData};
pub fn root_trust_anchors() -> Vec<TrustAnchor> {
vec![
TrustAnchor {
key_tag: 20326,
algorithm: Algorithm::RsaSha256,
digest_hex: "E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D".to_string(),
},
]
}
#[derive(Debug, Clone)]
pub struct TrustAnchor {
pub key_tag: u16,
pub algorithm: Algorithm,
pub digest_hex: String,
}
impl TrustAnchor {
pub fn matches_key(&self, key: &DnskeyData) -> bool {
if key.key_tag() != self.key_tag {
return false;
}
if key.algorithm != self.algorithm {
return false;
}
if !key.is_ksk() {
return false;
}
match key.algorithm {
Algorithm::RsaSha256 | Algorithm::RsaSha512 => {
if key.public_key.len() < 128 || key.public_key.len() > 1024 {
return false;
}
}
Algorithm::EcdsaP256Sha256 => {
if key.public_key.len() != 64 {
return false;
}
}
Algorithm::EcdsaP384Sha384 => {
if key.public_key.len() != 96 {
return false;
}
}
Algorithm::Ed25519 => {
if key.public_key.len() != 32 {
return false;
}
}
_ => return false,
}
true
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ValidationStatus {
Secure,
Insecure,
Bogus,
Indeterminate,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_root_trust_anchors() {
let anchors = root_trust_anchors();
assert!(!anchors.is_empty());
assert_eq!(anchors[0].key_tag, 20326);
assert_eq!(anchors[0].algorithm, Algorithm::RsaSha256);
}
}