hardcopy 1.0.1

Generate hard copies of keys, certs and secrets.
Documentation
use libhardcopy::{HardCopy, HardCopySectionContent};

const RULE: &str =
    "================================================================================";

/// Render a `HardCopy` to a plain-text string suitable for printing or saving.
///
/// Format:
/// ```text
/// ================================================================================
/// hardcopy v0.1.0
/// Date: YYYY-MM-DD
/// SHA-256: <hex>
/// ================================================================================
///
/// --- <Section Name> ---
/// 0001: word1 word2 word3 word4
/// ...
///
/// ================================================================================
/// SHA-256: <hex>
/// ================================================================================
/// ```
pub fn render(hardcopy: &HardCopy, checksum: &str) -> String {
    let version = env!("CARGO_PKG_VERSION");
    let date = chrono::Local::now().format("%Y-%m-%d").to_string();

    let mut out = String::new();

    out.push_str(RULE);
    out.push('\n');
    out.push_str(&format!("hardcopy v{}\n", version));
    out.push_str(&format!("Date: {}\n", date));
    out.push_str(&format!("SHA-256: {}\n", checksum));
    out.push_str(RULE);
    out.push('\n');

    for section in &hardcopy.sections {
        out.push('\n');
        out.push_str(&format!("--- {} ---\n", section.name));
        match &section.content {
            HardCopySectionContent::Words(lines) => {
                for line in lines {
                    out.push_str(line);
                    out.push('\n');
                }
            }
            HardCopySectionContent::Bytes(_) => {
                out.push_str("[binary section: see PDF output for QR codes]\n");
            }
        }
    }

    out.push('\n');
    out.push_str(RULE);
    out.push('\n');
    out.push_str(&format!("SHA-256: {}\n", checksum));
    out.push_str(RULE);
    out.push('\n');

    out
}