diff --git a/src/common/escape.rs b/src/common/escape.rs index 6501e51..1bc965a 100644 --- a/src/common/escape.rs +++ b/src/common/escape.rs @@ -3,6 +3,8 @@ use aho_corasick::AhoCorasick; use anyhow::Result; +use crate::types::errors::HuskError; + const REGEX_CONTROL_CHARS: &[&str] = &[ "\\", ".", "|", "(", ")", "*", "+", "?", "^", "$", "[", "]" ]; const REGEX_ESCAPED_CHARS: &[&str] @@ -36,10 +38,10 @@ pub fn regex_domain_unescape(value: &str) -> Result { if let Some(inner) = stripped.strip_suffix(">$") { Ok(inner.into()) } else { - Ok(value) + Err(HuskError::InvalidDomainName(value).into()) } } else { - Ok(value) + Err(HuskError::InvalidDomainName(value).into()) } } diff --git a/src/types/introducer.rs b/src/types/introducer.rs index a0c1a1e..d44e82c 100644 --- a/src/types/introducer.rs +++ b/src/types/introducer.rs @@ -9,6 +9,7 @@ use sequoia_openpgp::Cert; use crate::types::husk_context::HuskContext; use crate::common::crypto; +use crate::common::escape; #[derive(thiserror::Error, Debug)] pub enum IntroducerError { @@ -105,16 +106,28 @@ impl Introducer { } use std::fmt::{Display, Formatter}; -impl Display for Introducer { +impl Display for Introducer { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { // XXX: This is unsafe as ANSI control chars are not handled. let uids = self.cert.userids() .map(|u| String::from_utf8_lossy(u.userid().value()).to_string()) .collect::>() .join(", "); + writeln!(f, "Introducer: {}", self.cert.fingerprint())?; writeln!(f, " UserIDs: {}", uids)?; + + if let Some(regex_set) = self.certification.regular_expressions() { + for regex in regex_set.as_bytes().into_iter() { + let regex = String::from_utf8_lossy(regex); + if let Ok(domain) = escape::regex_domain_unescape(regex.to_string().as_str()) { + writeln!(f," Domain: {}", domain)?; + } else { + writeln!(f," RegEx: {}", regex)?; + } + } + } Ok(()) } }