3 releases
new 0.1.2 | Dec 16, 2024 |
---|---|
0.1.1 | Dec 16, 2024 |
0.1.0 | Dec 16, 2024 |
#8 in #pkg
105KB
2.5K
SLoC
zar
XAR archive reader/writer library that is fuzz-tested agains MacOS xar
.
Supports signing and verifying archives.
Installation
The easiest way to use zar
is via command line interface.
cargo install zar-cli
Usage
As a command-line application
# archive tmp dir
zar -cf tmp.xar /tmp
# extract the archive
zar -xf tmp.xar /tmp/extracted
# archive tmp dir and sign the archive
openssl genrsa -traditional -out private-key.pem 2048
openssl req -x509 -sha1 -days 1 -noenc -key private-key.pem -out cert.pem -subj /CN=Zar
zar --sign private-key.pem --cert cert.pem -cf tmp.xar /tmp
# verify and extract the archive
zar --trust cert.pem -xf tmp.xar /tmp/extracted
As a library
use std::fs::File;
use std::io::Error;
use zar::NoSigner;
fn create_archive() -> Result<(), Error> {
let file = File::create("archive.xar")?;
let mut builder = zar::UnsignedBuilder::new_unsigned(file);
builder.append_dir_all("/tmp", zar::Compression::default(), zar::no_extra_contents)?;
builder.finish()?;
Ok(())
}
fn extract_archive() -> Result<(), Error> {
let file = File::open("archive.xar")?;
let mut archive = zar::Archive::new(file)?;
for i in 0..archive.num_entries() {
let mut entry = archive.entry(i);
println!("{:?}", entry.file());
if let Some(mut reader) = entry.reader()? {
// read the entry...
}
}
Ok(())
}
Dependencies
~12MB
~213K SLoC