Rust Core Library & CLI
The core engine is implemented as a standalone Rust crate (plyqr) with zero dependencies on external C libraries.
1. CLI Commands
Section titled “1. CLI Commands”The CLI binary provides full-featured commands for operational key management and symbol generation.
Key Generation
Section titled “Key Generation”cargo run --release -- keygen <key_file>Generates a 32-byte cryptographically secure random key file.
Dual-Channel Encoding
Section titled “Dual-Channel Encoding”cargo run --release -- encode \ <public_file> \ <private_file> \ <key_file> \ <output_prefix> \ <version> \ <ec_level> \ <hidden_per_block> \ <noise_reserve> \ <private_ecc> \ <mask_pattern>Outputs:
<output_prefix>.svg: Vector format QR code.<output_prefix>.matrix: Serialized module matrix.<output_prefix>-public.svg: Baseline public-only reference vector.
Decoding
Section titled “Decoding”cargo run --release -- decode \ <matrix_file> \ <key_file> \ <public_out> \ <private_out>Extracts public and authenticated private payloads simultaneously.
Capacity Inspection
Section titled “Capacity Inspection”cargo run --release -- capacity <public_len> <version> <ec_level> <hidden_per_block> <noise_reserve> <private_ecc> <mask_pattern>Reports the exact maximum private payload byte capacity under the specified configuration parameters.
2. Rust API Usage
Section titled “2. Rust API Usage”Add plyqr to your Cargo.toml:
[dependencies]plyqr = { path = "../plyqr" }Encoding Example
Section titled “Encoding Example”use plyqr::{encode, Options, QrEcLevel};
fn main() -> Result<(), Box<dyn std::error::Error>> { let key: [u8; 32] = [0x42; 32]; // Replace with secure key let public_data = b"https://example.com/item/1024"; let private_data = b"CONFIDENTIAL_SERIAL_90821";
let mut options = Options::default(); options.version = 10; options.ec_level = QrEcLevel::Medium; options.hidden_per_block = 4; options.noise_reserve = 2; options.private_ecc = 8; options.public_utf8 = true;
let symbol = encode(public_data, private_data, &key, &options)?; let svg = symbol.to_svg(8)?; // Module pixel scale std::fs::write("qrcode.svg", svg)?;
Ok(())}