Skip to content

Commit e1849a7

Browse files
authored
Merge pull request #147 from rust-secure-code/readmes
Move doc headers to README.md and point rustdoc to them
2 parents 33ba39b + da1b1c4 commit e1849a7

4 files changed

Lines changed: 100 additions & 100 deletions

File tree

auditable-extract/README.md

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

auditable-extract/src/lib.rs

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,5 @@
11
#![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")]
583

594
#[cfg(feature = "wasm")]
605
mod wasm;

auditable-serde/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Parses and serializes the JSON dependency tree embedded in executables by the
2+
[`cargo auditable`](https://github.com/rust-secure-code/cargo-auditable).
3+
4+
This crate defines the data structures that a serialized to/from JSON
5+
and implements the serialization/deserialization routines via `serde`.
6+
It also provides optional conversions from [`cargo metadata`](https://docs.rs/cargo_metadata/)
7+
and to [`Cargo.lock`](https://docs.rs/cargo-lock) formats.
8+
9+
The [`VersionInfo`] struct is where all the magic happens, see the docs on it for more info.
10+
11+
## Basic usage
12+
13+
**Note:** this is a low-level crate that only implements JSON parsing. It rarely should be used directly.
14+
You probably want the higher-level [`auditable-info`](https://docs.rs/auditable-info) crate instead.
15+
16+
The following snippet demonstrates full extraction pipeline using this crate,
17+
including platform-specific executable handling via
18+
[`auditable-extract`](http://docs.rs/auditable-serde/) and decompression
19+
using the safe-Rust [`miniz_oxide`](http://docs.rs/miniz_oxide/):
20+
21+
```rust,ignore
22+
use std::io::{Read, BufReader};
23+
use std::{error::Error, fs::File, str::FromStr};
24+
25+
fn main() -> Result<(), Box<dyn Error>> {
26+
// Read the input
27+
let f = File::open("target/release/hello-world")?;
28+
let mut f = BufReader::new(f);
29+
let mut input_binary = Vec::new();
30+
f.read_to_end(&mut input_binary)?;
31+
// Extract the compressed audit data
32+
let compressed_audit_data = auditable_extract::raw_auditable_data(&input_binary)?;
33+
// Decompress it with your Zlib implementation of choice. We recommend miniz_oxide
34+
use miniz_oxide::inflate::decompress_to_vec_zlib;
35+
let decompressed_data = decompress_to_vec_zlib(&compressed_audit_data)
36+
.map_err(|_| "Failed to decompress audit data")?;
37+
let decompressed_data = String::from_utf8(decompressed_data)?;
38+
println!("{}", decompressed_data);
39+
// Parse the audit data to Rust data structures
40+
let dependency_tree = auditable_serde::VersionInfo::from_str(&decompressed_data);
41+
Ok(())
42+
}
43+
```

auditable-serde/src/lib.rs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,6 @@
11
#![forbid(unsafe_code)]
22
#![allow(clippy::redundant_field_names)]
3-
4-
//! Parses and serializes the JSON dependency tree embedded in executables by the
5-
//! [`cargo auditable`](https://github.com/rust-secure-code/cargo-auditable).
6-
//!
7-
//! This crate defines the data structures that a serialized to/from JSON
8-
//! and implements the serialization/deserialization routines via `serde`.
9-
//! It also provides optional conversions from [`cargo metadata`](https://docs.rs/cargo_metadata/)
10-
//! and to [`Cargo.lock`](https://docs.rs/cargo-lock) formats.
11-
//!
12-
//! The [`VersionInfo`] struct is where all the magic happens, see the docs on it for more info.
13-
//!
14-
//! ## Basic usage
15-
//!
16-
//! **Note:** this is a low-level crate that only implements JSON parsing. It rarely should be used directly.
17-
//! You probably want the higher-level [`auditable-info`](https://docs.rs/auditable-info) crate instead.
18-
//!
19-
//! The following snippet demonstrates full extraction pipeline, including
20-
//! platform-specific executable handling via
21-
//! [`auditable-extract`](http://docs.rs/auditable-serde/) and decompression
22-
//! using the safe-Rust [`miniz_oxide`](http://docs.rs/miniz_oxide/):
23-
//!
24-
//! ```rust,ignore
25-
//! use std::io::{Read, BufReader};
26-
//! use std::{error::Error, fs::File, str::FromStr};
27-
//!
28-
//! fn main() -> Result<(), Box<dyn Error>> {
29-
//! // Read the input
30-
//! let f = File::open("target/release/hello-world")?;
31-
//! let mut f = BufReader::new(f);
32-
//! let mut input_binary = Vec::new();
33-
//! f.read_to_end(&mut input_binary)?;
34-
//! // Extract the compressed audit data
35-
//! let compressed_audit_data = auditable_extract::raw_auditable_data(&input_binary)?;
36-
//! // Decompress it with your Zlib implementation of choice. We recommend miniz_oxide
37-
//! use miniz_oxide::inflate::decompress_to_vec_zlib;
38-
//! let decompressed_data = decompress_to_vec_zlib(&compressed_audit_data)
39-
//! .map_err(|_| "Failed to decompress audit data")?;
40-
//! let decompressed_data = String::from_utf8(decompressed_data)?;
41-
//! println!("{}", decompressed_data);
42-
//! // Parse the audit data to Rust data structures
43-
//! let dependency_tree = auditable_serde::VersionInfo::from_str(&decompressed_data);
44-
//! Ok(())
45-
//! }
46-
//! ```
3+
#![doc = include_str!("../README.md")]
474

485
mod validation;
496

0 commit comments

Comments
 (0)