use super::*;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PreparedExecution {
request: PageExecutionRequest,
source: Vec<u8>,
context: AuthoredOutputContext,
}
impl PreparedExecution {
pub fn request(&self) -> &PageExecutionRequest {
&self.request
}
pub fn source(&self) -> &[u8] {
&self.source
}
pub fn context(&self) -> &AuthoredOutputContext {
&self.context
}
#[cfg_attr(
not(target_os = "linux"),
allow(
dead_code,
reason = "The production engine is supported only on Linux."
)
)]
pub(crate) fn checked(
request: PageExecutionRequest,
source: Vec<u8>,
context: AuthoredOutputContext,
) -> Result<Self, RecordValidationError> {
if request.page.source_fingerprint != fingerprint_bytes(&source)
|| context.source() != &request.page.source
|| context.collection() != request.page.collection
{
return Err(RecordValidationError::Association);
}
let preparation = identity::validate_prepared(&request, &source)
.map_err(|_| RecordValidationError::Association)?;
if context.anchors() != &preparation.authored_anchors {
return Err(RecordValidationError::Association);
}
let parent = std::path::Path::new(request.page.source.path.as_str())
.parent()
.and_then(|p| p.to_str())
.filter(|p| !p.is_empty());
if request.page.working_directory.as_ref().map(|p| p.as_str()) != parent {
return Err(RecordValidationError::Association);
}
Ok(Self {
request,
source,
context,
})
}
}