14 releases (7 breaking)

new 0.8.0 Nov 11, 2024
0.7.0 Jul 30, 2024
0.6.1 Feb 19, 2024
0.6.0 Apr 27, 2023
0.1.0 Sep 7, 2020

#165 in Encoding

Download history 11845/week @ 2024-07-25 10598/week @ 2024-08-01 10058/week @ 2024-08-08 12751/week @ 2024-08-15 11430/week @ 2024-08-22 10783/week @ 2024-08-29 11238/week @ 2024-09-05 10941/week @ 2024-09-12 10933/week @ 2024-09-19 11697/week @ 2024-09-26 11727/week @ 2024-10-03 15589/week @ 2024-10-10 13311/week @ 2024-10-17 12860/week @ 2024-10-24 15532/week @ 2024-10-31 12221/week @ 2024-11-07

57,058 downloads per month
Used in 4 crates

MIT/Apache

14KB
221 lines

Parses and serializes the JSON dependency tree embedded in executables by the cargo auditable.

This crate defines the data structures that a serialized to/from JSON and implements the serialization/deserialization routines via serde.

The VersionInfo struct is where all the magic happens, see the docs on it for more info.

Basic usage

Note: this is a low-level crate that only implements JSON parsing. It rarely should be used directly. You probably want the higher-level auditable-info crate instead.

The following snippet demonstrates full extraction pipeline using this crate, including platform-specific executable handling via auditable-extract and decompression using the safe-Rust miniz_oxide:

use std::io::{Read, BufReader};
use std::{error::Error, fs::File, str::FromStr};

fn main() -> Result<(), Box<dyn Error>> {
    // Read the input
    let f = File::open("target/release/hello-world")?;
    let mut f = BufReader::new(f);
    let mut input_binary = Vec::new();
    f.read_to_end(&mut input_binary)?;
    // Extract the compressed audit data
    let compressed_audit_data = auditable_extract::raw_auditable_data(&input_binary)?;
    // Decompress it with your Zlib implementation of choice. We recommend miniz_oxide
    use miniz_oxide::inflate::decompress_to_vec_zlib;
    let decompressed_data = decompress_to_vec_zlib(&compressed_audit_data)
        .map_err(|_| "Failed to decompress audit data")?;
    let decompressed_data = String::from_utf8(decompressed_data)?;
    println!("{}", decompressed_data);
    // Parse the audit data to Rust data structures
    let dependency_tree = auditable_serde::VersionInfo::from_str(&decompressed_data);
    Ok(())
}

Dependencies

~0.7–1.7MB
~35K SLoC