Added hash verification to external source loading.
This commit is contained in:
parent
a5b8851e22
commit
9a8bbe9da9
2 changed files with 22 additions and 7 deletions
|
@ -567,13 +567,8 @@ impl CodeMapper for CodeMap {
|
||||||
};
|
};
|
||||||
|
|
||||||
if *file_map.external_src.borrow() == ExternalSource::AbsentOk {
|
if *file_map.external_src.borrow() == ExternalSource::AbsentOk {
|
||||||
let mut external_src = file_map.external_src.borrow_mut();
|
let src = self.file_loader.read_file(Path::new(&filename)).ok();
|
||||||
if let Ok(src) = self.file_loader.read_file(Path::new(&filename)) {
|
return file_map.add_external_src(src);
|
||||||
*external_src = ExternalSource::Present(src);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
*external_src = ExternalSource::AbsentErr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
|
|
|
@ -604,6 +604,26 @@ impl FileMap {
|
||||||
lines.push(pos);
|
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.
|
/// get a line from the list of pre-computed line-beginnings.
|
||||||
/// line-number here is 0-based.
|
/// line-number here is 0-based.
|
||||||
pub fn get_line(&self, line_number: usize) -> Option<Cow<str>> {
|
pub fn get_line(&self, line_number: usize) -> Option<Cow<str>> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue