#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![warn(missing_docs, clippy::pedantic)]
#![allow(clippy::missing_errors_doc)]
mod central;
mod container;
#[cfg(feature = "fs")]
mod dest;
mod error;
mod metadata;
mod name;
mod write;
pub use toml_edit;
pub use container::{metadata_of, Container};
#[cfg(feature = "fs")]
pub use dest::Destination;
pub use error::{EntryKind, Error, Malformed, NameError, Result, Unsupported};
pub use name::check_payload_name;
pub use write::{pack_file, pack_reader, rewrite_metadata, rewrite_metadata_bytes, Repack};
pub const METADATA_MEMBER: &str = "slipcase.metadata.toml";
pub const VERSION: &str = "1.0";
pub const VERSION_KEY: &str = "slipcase_version";
pub const PAYLOAD_FILE_KEY: &str = "payload.file";
#[derive(Debug)]
#[non_exhaustive]
pub enum Verdict {
Conformant,
NonConformant(Malformed),
Undetermined(Unsupported),
OutOfScope(String),
}
impl Verdict {
#[must_use]
pub fn is_conformant(&self) -> bool {
matches!(self, Self::Conformant)
}
}
impl std::fmt::Display for Verdict {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Conformant => f.write_str("conformant"),
Self::NonConformant(m) => write!(f, "not conformant: {m}"),
Self::Undetermined(u) => write!(f, "conformance cannot be established: {u}"),
Self::OutOfScope(v) => write!(
f,
"declares slipcase_version {v:?}, which this build does not implement, so it says nothing about conformance"
),
}
}
}
pub fn validate<R: std::io::Read + std::io::Seek>(reader: R) -> Result<Verdict> {
match Container::read(reader) {
Ok(c) if c.version() == VERSION => Ok(Verdict::Conformant),
Ok(c) => Ok(Verdict::OutOfScope(c.version().to_owned())),
Err(Error::Malformed(m)) => Ok(Verdict::NonConformant(m)),
Err(Error::Unsupported(u)) => Ok(Verdict::Undetermined(u)),
Err(e) => Err(e),
}
}