|
1 | 1 | #![forbid(unsafe_code)] |
2 | | - |
3 | | -//! Extracts the dependency tree information embedded in executables by |
4 | | -//! [`cargo auditable`](https://github.com/rust-secure-code/cargo-auditable). |
5 | | -//! |
6 | | -//! This crate parses platform-specific binary formats ([ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format), |
7 | | -//! [PE](https://en.wikipedia.org/wiki/Portable_Executable), |
8 | | -//! [Mach-O](https://en.wikipedia.org/wiki/Mach-O), [WASM](https://en.wikipedia.org/wiki/WebAssembly)) and obtains the compressed audit data. |
9 | | -//! |
10 | | -//! Unlike other binary parsing crates, it is specifically designed to be resilient to malicious input. |
11 | | -//! It 100% safe Rust (including all dependencies) and performs no heap allocations. |
12 | | -//! |
13 | | -//! ## Usage |
14 | | -//! |
15 | | -//! **Note:** this is a low-level crate that only implements binary parsing. It rarely should be used directly. |
16 | | -//! You probably want the higher-level [`auditable-info`](https://docs.rs/auditable-info) crate instead. |
17 | | -//! |
18 | | -//! The following snippet demonstrates full extraction pipeline using this crate, including decompression |
19 | | -//! using the safe-Rust [`miniz_oxide`](http://docs.rs/miniz_oxide/) and optional JSON parsing |
20 | | -//! via [`auditable-serde`](http://docs.rs/auditable-serde/): |
21 | | -//! |
22 | | -//! ```rust,ignore |
23 | | -//! use std::io::{Read, BufReader}; |
24 | | -//! use std::{error::Error, fs::File, str::FromStr}; |
25 | | -//! |
26 | | -//! fn main() -> Result<(), Box<dyn Error>> { |
27 | | -//! // Read the input |
28 | | -//! let f = File::open("target/release/hello-world")?; |
29 | | -//! let mut f = BufReader::new(f); |
30 | | -//! let mut input_binary = Vec::new(); |
31 | | -//! f.read_to_end(&mut input_binary)?; |
32 | | -//! // Extract the compressed audit data |
33 | | -//! let compressed_audit_data = auditable_extract::raw_auditable_data(&input_binary)?; |
34 | | -//! // Decompress it with your Zlib implementation of choice. We recommend miniz_oxide |
35 | | -//! use miniz_oxide::inflate::decompress_to_vec_zlib; |
36 | | -//! let decompressed_data = decompress_to_vec_zlib(&compressed_audit_data) |
37 | | -//! .map_err(|_| "Failed to decompress audit data")?; |
38 | | -//! let decompressed_data = String::from_utf8(decompressed_data)?; |
39 | | -//! println!("{}", decompressed_data); |
40 | | -//! // Parse the audit data to Rust data structures |
41 | | -//! let dependency_tree = auditable_serde::VersionInfo::from_str(&decompressed_data); |
42 | | -//! Ok(()) |
43 | | -//! } |
44 | | -//! ``` |
45 | | -//! |
46 | | -//! ## WebAssembly support |
47 | | -//! |
48 | | -//! We use a third-party crate [`wasmparser`](https://crates.io/crates/wasmparser) |
49 | | -//! created by Bytecode Alliance for parsing WebAssembly. |
50 | | -//! It is a robust and high-quality parser, but its dependencies contain some `unsafe` code, |
51 | | -//! most of which is not actually used in our build configuration. |
52 | | -//! |
53 | | -//! We have manually audited it and found it to be sound. |
54 | | -//! Still, the security guarantees for it are not as ironclad as for other parsers. |
55 | | -//! Because of that WebAssembly support is gated behind the optional `wasm` feature. |
56 | | -//! Be sure to [enable](https://doc.rust-lang.org/cargo/reference/features.html#dependency-features) |
57 | | -//! the `wasm` feature if you want to parse WebAssembly. |
| 2 | +#![doc = include_str!("../README.md")] |
58 | 3 |
|
59 | 4 | #[cfg(feature = "wasm")] |
60 | 5 | mod wasm; |
|
0 commit comments