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
|
@ -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>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue