Crate zar

Source
Expand description

§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(())
}

Re-exports§

pub use rsa;
pub use x509_cert;

Structs§

AppleRootCertVerifier
A RootCertVerifier that trusts only Apple root certificate.
ArchiveOptions
Archive reading and extraction options.
BuilderOptions
Builder options.
Device
Character device or block device information.
Encoding
Compression codec.
Entry
File entry that is currently being read.
ExtendedArchive
XAR archive with extra data.
ExtendedBuilder
XAR archive builder with extra data.
File
File entry.
FileChecksum
File hash.
FileData
Additional file entry data.
FileMode
File mode.
Link
Symbolic link information.
NoSigner
Archive Signer that produces unsigned archives.
RsaSigner
Archive Signer that uses RSA key to sign the archive.
Timestamp
UNIX timestamp.
TrustAny
A RootCertVerifier that trusts any certificate.
TrustCerts
A RootCertVerifier that trusts the supplied list of certificates.

Enums§

Checksum
A hash that is used to verify archive metadata and file contents.
ChecksumAlgo
Hash algorithm of Checksum.
Compression
Compression codec that is used to compress files and table of contents.
FileType
File type.
HardLink
A hard link.
XarDecoder
Decoder for Compression codec.

Traits§

RootCertVerifier
Root certificate verifier.
Signer
Archive signer.

Functions§

no_extra_contents
Use this function as extra argument to Builder::append_dir_all and Builder::append_raw calls to not append any extra data to the archive.

Type Aliases§

Archive
XAR archive without any extra data.
Builder
Signed XAR archive builder without extra data.
UnsignedBuilder
Unsigned XAR archive builder without extra data.