use serde::{Deserialize, Serialize};
use crate::frontmatter::Frontmatter;
use crate::identity::{ContentHash, IntegritySignature, NoteId, NoteVersion};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct NoteBody {
pub markdown: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Note {
pub id: NoteId,
pub frontmatter: Frontmatter,
pub body: NoteBody,
pub version: NoteVersion,
pub content_hash: ContentHash,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub integrity_signature: Option<IntegritySignature>,
}
impl Note {
pub fn verify_integrity(&self) -> Result<(), crate::error::DriftError> {
let computed = ContentHash::compute(&self.frontmatter, &self.body.markdown);
if computed == self.content_hash {
Ok(())
} else {
Err(crate::error::DriftError::ContentHashMismatch {
stored: self.content_hash,
computed,
})
}
}
}
#[derive(Debug, Clone)]
pub struct EffectiveNote {
pub id: NoteId,
pub frontmatter: Frontmatter,
pub body: NoteBody,
pub version: NoteVersion,
pub content_hash: ContentHash,
}