aboutsummaryrefslogtreecommitdiffstats
path: root/components/net/subresource_integrity.rs
diff options
context:
space:
mode:
authorPyfisch <pyfisch@gmail.com>2018-11-03 15:28:48 +0100
committerPyfisch <pyfisch@gmail.com>2018-11-03 15:29:01 +0100
commit2481ad25f82b1a5a005f3ecbf9ba4d2a88060b5b (patch)
treee6d28676c8bd0a4a842ec0ee6e953ce2d3aa1b9d /components/net/subresource_integrity.rs
parentba1ed11ced078686febc78b580773e8e93789b4d (diff)
downloadservo-2481ad25f82b1a5a005f3ecbf9ba4d2a88060b5b.tar.gz
servo-2481ad25f82b1a5a005f3ecbf9ba4d2a88060b5b.zip
Rustfmt net crate
Diffstat (limited to 'components/net/subresource_integrity.rs')
-rw-r--r--components/net/subresource_integrity.rs54
1 files changed, 29 insertions, 25 deletions
diff --git a/components/net/subresource_integrity.rs b/components/net/subresource_integrity.rs
index e0a7168de97..6abeb39149c 100644
--- a/components/net/subresource_integrity.rs
+++ b/components/net/subresource_integrity.rs
@@ -9,22 +9,13 @@ use std::iter::Filter;
use std::str::Split;
use std::sync::MutexGuard;
-const SUPPORTED_ALGORITHM: &'static [&'static str] = &[
- "sha256",
- "sha384",
- "sha512",
-];
+const SUPPORTED_ALGORITHM: &'static [&'static str] = &["sha256", "sha384", "sha512"];
pub type StaticCharVec = &'static [char];
/// A "space character" according to:
///
/// <https://html.spec.whatwg.org/multipage/#space-character>
-pub static HTML_SPACE_CHARACTERS: StaticCharVec = &[
- '\u{0020}',
- '\u{0009}',
- '\u{000a}',
- '\u{000c}',
- '\u{000d}',
-];
+pub static HTML_SPACE_CHARACTERS: StaticCharVec =
+ &['\u{0020}', '\u{0009}', '\u{000a}', '\u{000c}', '\u{000d}'];
#[derive(Clone)]
pub struct SriEntry {
pub alg: String,
@@ -79,9 +70,18 @@ pub fn parsed_metadata(integrity_metadata: &str) -> Vec<SriEntry> {
}
/// <https://w3c.github.io/webappsec-subresource-integrity/#getprioritizedhashfunction>
-pub fn get_prioritized_hash_function(hash_func_left: &str, hash_func_right: &str) -> Option<String> {
- let left_priority = SUPPORTED_ALGORITHM.iter().position(|s| s.to_owned() == hash_func_left).unwrap();
- let right_priority = SUPPORTED_ALGORITHM.iter().position(|s| s.to_owned() == hash_func_right).unwrap();
+pub fn get_prioritized_hash_function(
+ hash_func_left: &str,
+ hash_func_right: &str,
+) -> Option<String> {
+ let left_priority = SUPPORTED_ALGORITHM
+ .iter()
+ .position(|s| s.to_owned() == hash_func_left)
+ .unwrap();
+ let right_priority = SUPPORTED_ALGORITHM
+ .iter()
+ .position(|s| s.to_owned() == hash_func_right)
+ .unwrap();
if left_priority == right_priority {
return None;
@@ -91,7 +91,6 @@ pub fn get_prioritized_hash_function(hash_func_left: &str, hash_func_right: &str
} else {
Some(hash_func_right.to_owned())
}
-
}
/// <https://w3c.github.io/webappsec-subresource-integrity/#get-the-strongest-metadata>
@@ -100,8 +99,8 @@ pub fn get_strongest_metadata(integrity_metadata_list: Vec<SriEntry>) -> Vec<Sri
let mut current_algorithm = result[0].alg.clone();
for integrity_metadata in &integrity_metadata_list[1..] {
- let prioritized_hash = get_prioritized_hash_function(&integrity_metadata.alg,
- &*current_algorithm);
+ let prioritized_hash =
+ get_prioritized_hash_function(&integrity_metadata.alg, &*current_algorithm);
if prioritized_hash.is_none() {
result.push(integrity_metadata.clone());
} else if let Some(algorithm) = prioritized_hash {
@@ -116,9 +115,10 @@ pub fn get_strongest_metadata(integrity_metadata_list: Vec<SriEntry>) -> Vec<Sri
}
/// <https://w3c.github.io/webappsec-subresource-integrity/#apply-algorithm-to-response>
-fn apply_algorithm_to_response(body: MutexGuard<ResponseBody>,
- message_digest: MessageDigest)
- -> String {
+fn apply_algorithm_to_response(
+ body: MutexGuard<ResponseBody>,
+ message_digest: MessageDigest,
+) -> String {
if let ResponseBody::Done(ref vec) = *body {
let response_digest = hash(message_digest, vec).unwrap(); //Now hash
base64::encode(&response_digest)
@@ -171,8 +171,12 @@ pub fn is_response_integrity_valid(integrity_metadata: &str, response: &Response
false
}
-pub fn split_html_space_chars<'a>(s: &'a str) ->
- Filter<Split<'a, StaticCharVec>, fn(&&str) -> bool> {
- fn not_empty(&split: &&str) -> bool { !split.is_empty() }
- s.split(HTML_SPACE_CHARACTERS).filter(not_empty as fn(&&str) -> bool)
+pub fn split_html_space_chars<'a>(
+ s: &'a str,
+) -> Filter<Split<'a, StaticCharVec>, fn(&&str) -> bool> {
+ fn not_empty(&split: &&str) -> bool {
+ !split.is_empty()
+ }
+ s.split(HTML_SPACE_CHARACTERS)
+ .filter(not_empty as fn(&&str) -> bool)
}