about summary refs log tree commit diff
path: root/src/libsyntax_pos
diff options
context:
space:
mode:
authorInokentiy Babushkin <twk@twki.de>2017-06-11 13:48:54 +0200
committerInokentiy Babushkin <twk@twki.de>2017-06-11 13:48:54 +0200
commit9a8bbe9da9a9c5537379ee38e755cf35c7a4fc96 (patch)
treefd49c9be5cd815899e40b1bcad7b54b300d57652 /src/libsyntax_pos
parenta5b8851e220d7a80222ea04d242603dd3392d17b (diff)
downloadrust-9a8bbe9da9a9c5537379ee38e755cf35c7a4fc96.tar.gz
rust-9a8bbe9da9a9c5537379ee38e755cf35c7a4fc96.zip
Added hash verification to external source loading.
Diffstat (limited to 'src/libsyntax_pos')
-rw-r--r--src/libsyntax_pos/lib.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs
index 0bac896f6a2..719c25e2410 100644
--- a/src/libsyntax_pos/lib.rs
+++ b/src/libsyntax_pos/lib.rs
@@ -604,6 +604,26 @@ impl FileMap {
         lines.push(pos);
     }
 
+    /// add externally loaded source.
+    /// if the hash of the input doesn't match or no input is supplied via None,
+    /// it is interpreted as an error and the corresponding enum variant is set.
+    pub fn add_external_src(&self, src: Option<String>) -> bool {
+        let mut external_src = self.external_src.borrow_mut();
+        if let Some(src) = src {
+            let mut hasher: StableHasher<u128> = StableHasher::new();
+            hasher.write(src.as_bytes());
+
+            if hasher.finish() == self.src_hash {
+                *external_src = ExternalSource::Present(src);
+                return true;
+            }
+        } else {
+            *external_src = ExternalSource::AbsentErr;
+        }
+
+        false
+    }
+
     /// get a line from the list of pre-computed line-beginnings.
     /// line-number here is 0-based.
     pub fn get_line(&self, line_number: usize) -> Option<Cow<str>> {