#archive #xar #macos #digital-signature

zar

XAR archive reader/writer library. Fuzz-tested against MacOS xar.

5 releases

0.1.4 Feb 16, 2025
0.1.3 Feb 2, 2025
0.1.2 Dec 16, 2024
0.1.1 Dec 16, 2024
0.1.0 Dec 16, 2024

#480 in Encoding

Download history 318/week @ 2024-12-14 25/week @ 2024-12-21 3/week @ 2024-12-28 137/week @ 2025-02-01 8/week @ 2025-02-08 124/week @ 2025-02-15 11/week @ 2025-02-22 13/week @ 2025-03-01 1/week @ 2025-03-08

150 downloads per month
Used in 2 crates

MIT license

90KB
2K SLoC

zar

Crates.io Version Docs dependency status

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

~11MB
~203K SLoC