Skip to content

Rust Core Library & CLI

The core engine is implemented as a standalone Rust crate (plyqr) with zero dependencies on external C libraries.


The CLI binary provides full-featured commands for operational key management and symbol generation.

Terminal window
cargo run --release -- keygen <key_file>

Generates a 32-byte cryptographically secure random key file.

Terminal window
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.
Terminal window
cargo run --release -- decode \
<matrix_file> \
<key_file> \
<public_out> \
<private_out>

Extracts public and authenticated private payloads simultaneously.

Terminal window
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.


Add plyqr to your Cargo.toml:

[dependencies]
plyqr = { path = "../plyqr" }
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(())
}