use serde::{Deserialize, Serialize};
use thiserror::Error;
use super::record::{SnapshotAttestation, SnapshotRecord};
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum SnapshotAttestationSubmissionError {
#[error("snapshot_attestation.record_digest does not match snapshot_record.record_digest()")]
DigestMismatch,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct SnapshotAttestationSubmission {
snapshot_record: SnapshotRecord,
snapshot_attestation: SnapshotAttestation,
}
impl SnapshotAttestationSubmission {
pub fn new(snapshot_record: SnapshotRecord, snapshot_attestation: SnapshotAttestation) -> Self {
Self {
snapshot_record,
snapshot_attestation,
}
}
pub fn snapshot_record(&self) -> &SnapshotRecord {
&self.snapshot_record
}
pub fn snapshot_attestation(&self) -> &SnapshotAttestation {
&self.snapshot_attestation
}
pub fn validate_digest_consistency(&self) -> Result<(), SnapshotAttestationSubmissionError> {
if *self.snapshot_attestation.record_digest() == self.snapshot_record.record_digest() {
Ok(())
} else {
Err(SnapshotAttestationSubmissionError::DigestMismatch)
}
}
}