Added hash verification to external source loading.

This commit is contained in:
Inokentiy Babushkin 2017-06-11 13:48:54 +02:00
parent a5b8851e22
commit 9a8bbe9da9
No known key found for this signature in database
GPG key ID: 7EFC8EC5224DE8EC
2 changed files with 22 additions and 7 deletions

View file

@ -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>> {