Rustfmt net crate

This commit is contained in:
Pyfisch 2018-11-03 15:28:48 +01:00
parent ba1ed11ced
commit 2481ad25f8
30 changed files with 4957 additions and 2870 deletions

View file

@ -16,11 +16,15 @@ pub struct HstsEntry {
pub host: String,
pub include_subdomains: bool,
pub max_age: Option<u64>,
pub timestamp: Option<u64>
pub timestamp: Option<u64>,
}
impl HstsEntry {
pub fn new(host: String, subdomains: IncludeSubdomains, max_age: Option<u64>) -> Option<HstsEntry> {
pub fn new(
host: String,
subdomains: IncludeSubdomains,
max_age: Option<u64>,
) -> Option<HstsEntry> {
if host.parse::<Ipv4Addr>().is_ok() || host.parse::<Ipv6Addr>().is_ok() {
None
} else {
@ -28,7 +32,7 @@ impl HstsEntry {
host: host,
include_subdomains: (subdomains == IncludeSubdomains::Included),
max_age: max_age,
timestamp: Some(time::get_time().sec as u64)
timestamp: Some(time::get_time().sec as u64),
})
}
}
@ -37,9 +41,9 @@ impl HstsEntry {
match (self.max_age, self.timestamp) {
(Some(max_age), Some(timestamp)) => {
(time::get_time().sec as u64) - timestamp >= max_age
}
},
_ => false
_ => false,
}
}
@ -59,7 +63,9 @@ pub struct HstsList {
impl HstsList {
pub fn new() -> HstsList {
HstsList { entries_map: HashMap::new() }
HstsList {
entries_map: HashMap::new(),
}
}
/// Create an `HstsList` from the bytes of a JSON preload file.
@ -107,9 +113,9 @@ impl HstsList {
}
fn has_subdomain(&self, host: &str, base_domain: &str) -> bool {
self.entries_map.get(base_domain).map_or(false, |entries| {
entries.iter().any(|e| e.matches_subdomain(host))
})
self.entries_map.get(base_domain).map_or(false, |entries| {
entries.iter().any(|e| e.matches_subdomain(host))
})
}
pub fn push(&mut self, entry: HstsEntry) {
@ -118,7 +124,10 @@ impl HstsList {
let have_domain = self.has_domain(&entry.host, base_domain);
let have_subdomain = self.has_subdomain(&entry.host, base_domain);
let entries = self.entries_map.entry(base_domain.to_owned()).or_insert(vec![]);
let entries = self
.entries_map
.entry(base_domain.to_owned())
.or_insert(vec![]);
if !have_domain && !have_subdomain {
entries.push(entry);
} else if !have_subdomain {
@ -136,7 +145,10 @@ impl HstsList {
if url.scheme() != "http" {
return;
}
if url.domain().map_or(false, |domain| self.is_host_secure(domain)) {
if url
.domain()
.map_or(false, |domain| self.is_host_secure(domain))
{
url.as_mut_url().set_scheme("https").unwrap();
}
}