Move the domain to regex conversion functionality to common.
- Move the code that converts a domain to a regular expression in `src/commands/pki/link.rs` to `src/common/pki/certify.rs`.
This commit is contained in:
parent
712bb1991b
commit
d303694e9d
@ -152,6 +152,7 @@ pub fn authorize(sq: Sq, mut c: authorize::Command)
|
|||||||
true, // User supplied user IDs.
|
true, // User supplied user IDs.
|
||||||
&[(c.amount, c.expiration)],
|
&[(c.amount, c.expiration)],
|
||||||
c.depth,
|
c.depth,
|
||||||
|
&[], // Domain.
|
||||||
&c.regex[..],
|
&c.regex[..],
|
||||||
c.local,
|
c.local,
|
||||||
c.non_revocable,
|
c.non_revocable,
|
||||||
|
@ -155,7 +155,7 @@ pub fn certify(sq: Sq, mut c: certify::Command)
|
|||||||
true, // User supplied user IDs.
|
true, // User supplied user IDs.
|
||||||
&[(c.amount, c.expiration)],
|
&[(c.amount, c.expiration)],
|
||||||
0,
|
0,
|
||||||
&[][..],
|
&[][..], &[][..], // Domain, regex.
|
||||||
c.local,
|
c.local,
|
||||||
c.non_revocable,
|
c.non_revocable,
|
||||||
¬ations[..],
|
¬ations[..],
|
||||||
|
@ -268,39 +268,12 @@ pub fn add(sq: Sq, c: link::AddCommand)
|
|||||||
if domain == "*" {
|
if domain == "*" {
|
||||||
star = true;
|
star = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = UserIDQueryParams::is_domain(&domain) {
|
|
||||||
return Err(err).context(format!(
|
|
||||||
"{:?} is not a valid domain", domain));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's a catch all, we don't need to add any regular
|
// If there's a catch all, we don't need to add any regular
|
||||||
// expressions.
|
// expressions.
|
||||||
if star {
|
if star {
|
||||||
regex = Vec::new();
|
regex = Vec::new();
|
||||||
} else {
|
|
||||||
for mut domain in c.ca.into_iter() {
|
|
||||||
// Escape any control characters.
|
|
||||||
const CONTROL: &[(&str, &str)] = &[
|
|
||||||
(".", "\\."),
|
|
||||||
("|", "\\|"),
|
|
||||||
("(", "\\("),
|
|
||||||
(")", "\\)"),
|
|
||||||
("*", "\\*"),
|
|
||||||
("+", "\\+"),
|
|
||||||
("?", "\\?"),
|
|
||||||
("^", "\\^"),
|
|
||||||
("$", "\\$"),
|
|
||||||
("[", "\\["),
|
|
||||||
("]", "\\]"),
|
|
||||||
];
|
|
||||||
for (c, e) in CONTROL.iter() {
|
|
||||||
domain = domain.replace(c, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
regex.push(format!("<[^>]+[@.]{}>$", domain));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let notations = parse_notations(c.notation)?;
|
let notations = parse_notations(c.notation)?;
|
||||||
@ -333,6 +306,11 @@ pub fn add(sq: Sq, c: link::AddCommand)
|
|||||||
user_supplied_userids,
|
user_supplied_userids,
|
||||||
&templates,
|
&templates,
|
||||||
trust_depth,
|
trust_depth,
|
||||||
|
if star {
|
||||||
|
&[][..]
|
||||||
|
} else {
|
||||||
|
&c.ca[..]
|
||||||
|
},
|
||||||
®ex[..],
|
®ex[..],
|
||||||
true, // Local.
|
true, // Local.
|
||||||
false, // Non-revocable.
|
false, // Non-revocable.
|
||||||
@ -375,7 +353,7 @@ pub fn retract(sq: Sq, c: link::RetractCommand)
|
|||||||
user_supplied_userids,
|
user_supplied_userids,
|
||||||
&[(TrustAmount::None, Expiration::Never)],
|
&[(TrustAmount::None, Expiration::Never)],
|
||||||
0,
|
0,
|
||||||
&[][..],
|
&[][..], &[][..], // Domain, regex.
|
||||||
true, // Local.
|
true, // Local.
|
||||||
false, // Non-revocable.
|
false, // Non-revocable.
|
||||||
¬ations[..],
|
¬ations[..],
|
||||||
|
@ -20,6 +20,7 @@ use openpgp::types::SignatureType;
|
|||||||
|
|
||||||
use sequoia_cert_store as cert_store;
|
use sequoia_cert_store as cert_store;
|
||||||
use cert_store::StoreUpdate;
|
use cert_store::StoreUpdate;
|
||||||
|
use cert_store::store::UserIDQueryParams;
|
||||||
|
|
||||||
use crate::Sq;
|
use crate::Sq;
|
||||||
use crate::cli::types::Expiration;
|
use crate::cli::types::Expiration;
|
||||||
@ -166,6 +167,7 @@ pub fn certify(sq: &Sq,
|
|||||||
user_supplied_userids: bool,
|
user_supplied_userids: bool,
|
||||||
templates: &[(TrustAmount<u8>, Expiration)],
|
templates: &[(TrustAmount<u8>, Expiration)],
|
||||||
trust_depth: u8,
|
trust_depth: u8,
|
||||||
|
domain: &[String],
|
||||||
regex: &[String],
|
regex: &[String],
|
||||||
local: bool,
|
local: bool,
|
||||||
non_revocable: bool,
|
non_revocable: bool,
|
||||||
@ -192,6 +194,34 @@ pub fn certify(sq: &Sq,
|
|||||||
let mut base
|
let mut base
|
||||||
= SignatureBuilder::new(SignatureType::GenericCertification);
|
= SignatureBuilder::new(SignatureType::GenericCertification);
|
||||||
|
|
||||||
|
for domain in domain {
|
||||||
|
if let Err(err) = UserIDQueryParams::is_domain(domain) {
|
||||||
|
return Err(err).context(format!(
|
||||||
|
"{:?} is not a valid domain", domain));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escape any control characters.
|
||||||
|
const CONTROL: &[(&str, &str)] = &[
|
||||||
|
(".", "\\."),
|
||||||
|
("|", "\\|"),
|
||||||
|
("(", "\\("),
|
||||||
|
(")", "\\)"),
|
||||||
|
("*", "\\*"),
|
||||||
|
("+", "\\+"),
|
||||||
|
("?", "\\?"),
|
||||||
|
("^", "\\^"),
|
||||||
|
("$", "\\$"),
|
||||||
|
("[", "\\["),
|
||||||
|
("]", "\\]"),
|
||||||
|
];
|
||||||
|
|
||||||
|
let mut domain = domain.to_string();
|
||||||
|
for (c, e) in CONTROL.iter() {
|
||||||
|
domain = domain.replace(c, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
base = base.add_regular_expression(format!("<[^>]+[@.]{}>$", domain))?;
|
||||||
|
}
|
||||||
for regex in regex {
|
for regex in regex {
|
||||||
base = base.add_regular_expression(regex)?;
|
base = base.add_regular_expression(regex)?;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user