mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 12:35:28 +00:00
use match
This commit is contained in:
parent
23d4167511
commit
462bba605d
1 changed files with 13 additions and 11 deletions
|
|
@ -210,25 +210,27 @@ impl CertStore {
|
||||||
|
|
||||||
impl ResolvesServerCert for CertStore {
|
impl ResolvesServerCert for CertStore {
|
||||||
fn resolve(&self, client_hello: ClientHello<'_>) -> Option<Arc<CertifiedKey>> {
|
fn resolve(&self, client_hello: ClientHello<'_>) -> Option<Arc<CertifiedKey>> {
|
||||||
if let Some(name) = client_hello.server_name() {
|
match client_hello.server_name() {
|
||||||
let name: &str = name;
|
|
||||||
// The certificate list is sorted so the longest match will always
|
// The certificate list is sorted so the longest match will always
|
||||||
// appear first. We have to find the first that is either this
|
// appear first. We have to find the first that is either this
|
||||||
// domain or a parent domain of the current one.
|
// domain or a parent domain of the current one.
|
||||||
self.certs
|
Some(name) => {
|
||||||
.iter()
|
let name: &str = name;
|
||||||
.find(|(s, _)| name.ends_with(s))
|
self.certs
|
||||||
// only the key is interesting
|
.iter()
|
||||||
.map(|(_, k)| k)
|
.find(|(s, _)| name.ends_with(s))
|
||||||
.cloned()
|
// only the key is interesting
|
||||||
} else {
|
.map(|(_, k)| k)
|
||||||
|
.cloned()
|
||||||
|
}
|
||||||
// Fallback to default cert.
|
// Fallback to default cert.
|
||||||
// * must exist in the `.certificates` root
|
// * must exist in the `.certificates` root
|
||||||
// * CN value can be any
|
// * CN value can be any
|
||||||
self.certs
|
None => self
|
||||||
|
.certs
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(domain, _)| domain.is_empty())
|
.find(|(domain, _)| domain.is_empty())
|
||||||
.map(|(_, key)| Arc::clone(key))
|
.map(|(_, key)| Arc::clone(key)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue