Skip to content

Commit 83b2e22

Browse files
committed
docs: add comprehensive Rustdoc comments and fix inaccurate help text
Add module-level documentation (//!) and doc comments (///) to all source files to support `cargo doc` and prepare for `cargo rdme` README generation. Changes per file: - main.rs: Add top-level crate documentation with usage overview and subcommand table; add #![deny(missing_docs)] to enforce documentation on public items; fix SnpGuestCmd variant descriptions to match actual behavior - report.rs: Document ReportArgs fields accurately; fix --random help (was misleading about default file path); fix --platform help to describe vTPM retrieval on Azure CVMs - certs.rs: Document CertPaths, CertFormat, CertificatesArgs, and all public functions - fetch.rs: Document FetchCmd, Endorsement, ProcType enums; document all submodule Args structs and functions; improve fetch ca/vcek/crl argument descriptions - verify.rs: Fix critical help text errors from issue virtee#132: --tcb now correctly described as "verify TCB only (skip signature)" instead of "run TCB verification exclusively"; --signature now correctly described as "verify signature only (skip TCB)" instead of "run signature verification exclusively"; document decode_hex_or_decimal behavior mismatch (issue virtee#135); document all verification functions - display.rs: Document DisplayCmd and subcommand functions - key.rs: Document KeyArgs with accurate Guest Field Select bit descriptions; document message version auto-selection behavior - ok.rs: Document SEV status MSR bitfield and capability test framework - preattestation.rs: Document all generate subcommands (measurement, ovmf-hash, id-block, key-digest) with accurate argument descriptions - clparser/mod.rs: Document auto-radix parser and FromStrRadix trait - hyperv/mod.rs: Document Hyper-V detection logic and vTPM report retrieval Source of truth: actual code behavior on main branch and the corrected README.md from PR virtee#139 (docs-overhaul branch). https://claude.ai/code/session_01YFz1JMARmZYNFwTQ6juM7Z
1 parent 19fc1af commit 83b2e22

11 files changed

Lines changed: 457 additions & 145 deletions

File tree

src/certs.rs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// This file contains code related to managing certificates. It defines a structure for managing certificate paths (`CertPaths`) and functions for obtaining extended certificates from the AMD Secure Processor.
2+
3+
//! Certificate management for the `certificates` subcommand.
4+
//!
5+
//! This module provides structures and functions for requesting certificates
6+
//! cached in hypervisor memory via the AMD Secure Processor
7+
//! (`SNP_GET_EXT_REPORT` ioctl), converting certificate formats (PEM/DER),
8+
//! and writing certificates to disk.
39
410
use crate::fetch::Endorsement;
511

@@ -17,18 +23,25 @@ use sev::{
1723
firmware::{guest::Firmware, host::CertType},
1824
};
1925

26+
/// Paths to the three certificates that form an SNP certificate chain:
27+
/// ARK (AMD Root Key), ASK (AMD SEV Key) or ASVK (AMD SEV-VLEK Key),
28+
/// and VCEK (Versioned Chip Endorsement Key) or VLEK (Versioned Loaded Endorsement Key).
2029
pub struct CertPaths {
30+
/// Path to the AMD Root Key certificate.
2131
pub ark_path: PathBuf,
32+
/// Path to the AMD SEV Key (or ASVK for VLEK chains) certificate.
2233
pub ask_path: PathBuf,
34+
/// Path to the VCEK or VLEK certificate.
2335
pub vek_path: PathBuf,
2436
}
2537

38+
/// Supported certificate encoding formats.
2639
#[derive(ValueEnum, Clone, Copy)]
2740
pub enum CertFormat {
28-
/// Certificates are encoded in PEM format.
41+
/// PEM (Privacy-Enhanced Mail) encoding.
2942
Pem,
3043

31-
/// Certificates are encoded in DER format.
44+
/// DER (Distinguished Encoding Rules) binary encoding.
3245
Der,
3346
}
3447

@@ -52,7 +65,10 @@ impl FromStr for CertFormat {
5265
}
5366
}
5467

55-
// Function that will convert a cert path into a snp Certificate
68+
/// Read a certificate file and convert it into an SNP [`Certificate`].
69+
///
70+
/// If `cert_path` is empty, falls back to looking in `./certs/` for
71+
/// `{cert_type}.pem` or `{cert_type}.der`.
5672
pub fn convert_path_to_cert(
5773
cert_path: &PathBuf,
5874
cert_type: &str,
@@ -88,7 +104,7 @@ pub fn convert_path_to_cert(
88104
Ok(Certificate::from_bytes(&buf)?)
89105
}
90106

91-
// Tryfrom function that takes in 3 certificate paths returns a snp Certificate Chain
107+
/// Build an SNP [`Chain`] from three certificate file paths (ARK, ASK/ASVK, VCEK/VLEK).
92108
impl TryFrom<CertPaths> for Chain {
93109
type Error = anyhow::Error;
94110
fn try_from(content: CertPaths) -> Result<Self, Self::Error> {
@@ -117,7 +133,11 @@ impl TryFrom<CertPaths> for Chain {
117133
}
118134
}
119135

120-
// Function used to write provided cert into desired directory.
136+
/// Write a certificate to a file in the specified encoding format.
137+
///
138+
/// The filename is derived from the certificate type and encoding
139+
/// (e.g., `vcek.pem`, `ark.der`). For VLEK endorsement with an ASK
140+
/// cert type, the file is named `asvk`.
121141
pub fn write_cert(
122142
path: &Path,
123143
cert_type: &CertType,
@@ -164,17 +184,26 @@ pub fn write_cert(
164184
Ok(())
165185
}
166186

187+
/// CLI arguments for the `certificates` subcommand.
188+
///
189+
/// Requests certificates from the hypervisor extended memory via the AMD
190+
/// Secure Processor and stores them in the specified directory.
167191
#[derive(Parser)]
168192
pub struct CertificatesArgs {
169-
/// Specify encoding to use for certificates.
193+
/// Certificate encoding format (PEM or DER).
170194
#[arg(value_name = "encoding", required = true, ignore_case = true)]
171195
pub encoding: CertFormat,
172196

173-
/// Directory to store certificates in. Required if requesting an extended-report.
197+
/// Directory to store the certificates in. Created if it does not exist.
174198
#[arg(value_name = "certs-dir", required = true)]
175199
pub certs_dir: PathBuf,
176200
}
177201

202+
/// Request extended certificates from the AMD Secure Processor and write them to disk.
203+
///
204+
/// Uses `SNP_GET_EXT_REPORT` to obtain certificates cached in the hypervisor
205+
/// extended memory. Each certificate is written to the specified directory in the
206+
/// chosen encoding format.
178207
pub fn get_ext_certs(args: CertificatesArgs) -> Result<()> {
179208
let mut sev_fw: Firmware = Firmware::open().context("failed to open SEV firmware device.")?;
180209

src/clparser/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// This file contains custom u32/u64 parsers for supporting decimal, hexadecimal and binary formats.
2+
3+
//! Custom integer parsers for CLI arguments supporting multiple radix formats.
4+
//!
5+
//! Provides a clap-compatible value parser that accepts integers in:
6+
//! - Decimal (e.g., `63`)
7+
//! - Hexadecimal with `0x` prefix (e.g., `0x3f`)
8+
//! - Binary with `0b` prefix (e.g., `0b111111`)
39
410
use std::num::ParseIntError;
511

12+
/// Parse an integer string with automatic radix detection.
13+
///
14+
/// Supported formats:
15+
/// - `0x...` — hexadecimal
16+
/// - `0b...` — binary
17+
/// - anything else — decimal
618
pub fn parse_int_auto_radix<T>(s: &str) -> Result<T, ParseIntError>
719
where
820
T: FromStrRadix,
@@ -16,7 +28,11 @@ where
1628
}
1729
}
1830

31+
/// Trait for parsing integers from a string with a given radix.
32+
///
33+
/// Implemented for [`u32`] and [`u64`].
1934
pub trait FromStrRadix: Sized {
35+
/// Parse `src` as an integer in the given `radix` (2, 10, or 16).
2036
fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
2137
}
2238

src/display.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// This file contains the subcommands for displaying attestation reports and derived keys.
2+
3+
//! Display attestation reports and derived keys in human-readable form.
4+
//!
5+
//! This module provides the `display` subcommand family:
6+
//! - `display report` — Print an attestation report's contents to the terminal.
7+
//! - `display key` — Print a derived key in hex format to the terminal.
38
49
use super::*;
510
use std::path::PathBuf;
611

12+
/// Subcommands for displaying attestation data in human-readable form.
713
#[derive(Subcommand)]
814
pub enum DisplayCmd {
9-
/// Display an attestation report in console.
15+
/// Print the contents of an attestation report to the terminal.
1016
Report(report_display::Args),
1117

12-
/// Display the derived key in console.
18+
/// Print a derived key in hex format to the terminal.
1319
Key(key_display::Args),
1420
}
1521

22+
/// Dispatch to the appropriate display subcommand handler.
1623
pub fn cmd(cmd: DisplayCmd, quiet: bool) -> Result<()> {
1724
match cmd {
1825
DisplayCmd::Report(args) => report_display::display_attestation_report(args, quiet),
@@ -22,14 +29,15 @@ pub fn cmd(cmd: DisplayCmd, quiet: bool) -> Result<()> {
2229
mod report_display {
2330
use super::*;
2431

32+
/// CLI arguments for `display report`.
2533
#[derive(Parser)]
2634
pub struct Args {
27-
/// Path to attestation report to display.
35+
/// Path to the attestation report file to display.
2836
#[arg(value_name = "att-report-path", required = true)]
2937
pub att_report_path: PathBuf,
3038
}
3139

32-
// Print attestation report in console
40+
/// Read and print an attestation report to the console.
3341
pub fn display_attestation_report(args: Args, quiet: bool) -> Result<()> {
3442
let att_report = report::read_report(args.att_report_path)
3543
.context("Could not open attestation report")?;
@@ -45,14 +53,15 @@ mod report_display {
4553
mod key_display {
4654
use super::*;
4755

56+
/// CLI arguments for `display key`.
4857
#[derive(Parser)]
4958
pub struct Args {
50-
/// Path of key to be displayed.
59+
/// Path to the derived key file to display.
5160
#[arg(value_name = "key-path", required = true)]
5261
pub key_path: PathBuf,
5362
}
5463

55-
// Print derived key in console
64+
/// Read and print a derived key in hex format (16 bytes per line).
5665
pub fn display_derived_key(args: Args, quiet: bool) -> Result<()> {
5766
let key_report = key::read_key(args.key_path).context("Could not open key")?;
5867

@@ -62,7 +71,6 @@ mod key_display {
6271
if (i % 16) == 0 {
6372
keydata.push('\n');
6473
}
65-
//Displaying key in Hex format
6674
keydata.push_str(&format!("{byte:02x} "));
6775
}
6876
keydata.push('\n');

0 commit comments

Comments
 (0)