| Crates.io | rzmq_cli |
| lib.rs | rzmq_cli |
| version | 0.1.0 |
| created_at | 2025-06-10 04:55:40.932371+00 |
| updated_at | 2025-06-10 04:55:40.932371+00 |
| description | Command Line Utility for RZMQ, an asynchronous, pure-Rust implementation of ZeroMQ (ØMQ) messaging patterns, with optional io_uring acceleration on Linux. |
| homepage | https://github.com/excsn/rzmq |
| repository | https://github.com/excsn/rzmq |
| max_upload_size | |
| id | 1706657 |
| size | 27,352 |
rzmq)Command-line utility for RZMQ, a pure-Rust asynchronous ZeroMQ implementation.
License: Mozilla Public License v2.0 (MPL-2.0)
The rzmq CLI provides helpful utilities for working with the RZMQ library. Currently, its primary function is to generate cryptographic keypairs for use with RZMQ's security mechanisms, such as Noise_XX.
cargo install rzmq_cli
rzmq_cli repository.
# Example if it's in the main rzmq repo in a subdirectory:
git clone https://github.com/your_username/rzmq.git
cd rzmq/rzmq_cli
# Or if it's a standalone repo:
# git clone https://github.com/your_username/rzmq_cli.git
# cd rzmq_cli
cargo install --path .
This will install the rzmq binary into your Cargo bin directory (usually ~/.cargo/bin/). Ensure this directory is in your system's PATH.The CLI is invoked using the rzmq command, followed by subcommands.
The keygen subcommand is used to generate cryptographic keys.
To generate a static X25519 keypair (secret key and public key) for the Noise_XX protocol pattern:
rzmq keygen noise-xx --name <KEY_NAME> [OPTIONS]
Arguments & Options:
--name <KEY_NAME> (Required, alias: -n)
<KEY_NAME> is "server", files server.noise.sk (secret key) and server.noise.pk (public key) will be created.--output-dir <DIR> (Optional, alias: -o, default: current directory .)
--file-format <FORMAT> (Optional, default: hex)
hex: Keys are stored as hexadecimal strings. (Default)base64: Keys are stored as URL-safe Base64 strings (no padding).binary: Keys are stored as raw 32-byte binary data.--display-format <FORMAT> (Optional, default: hex)
hex: Display keys as hexadecimal strings. (Default)base64: Display keys as URL-safe Base64 strings.rust: Display keys as Rust [u8; 32] array literals, suitable for embedding in code.--force (Optional, alias: -f)
File Naming Convention:
<KEY_NAME>.noise.sk<KEY_NAME>.noise.pkFile Permissions (Unix-like systems):
.noise.sk) are created with permissions 0600 (read/write for owner only)..noise.pk) are created with permissions 0644 (read/write for owner, read-only for group and others).Examples:
Generate a keypair named "my_server" in the current directory, with hex format in files and hex display on stdout (default formats):
rzmq keygen noise-xx --name my_server
Output will show keys in hex and create ./my_server.noise.sk and ./my_server.noise.pk containing hex strings.
Generate a keypair named "client01", save raw binary keys into a keys/ subdirectory, and display keys as Rust arrays:
rzmq keygen noise-xx --name client01 --output-dir ./keys --file-format binary --display-format rust
This creates ./keys/client01.noise.sk and ./keys/client01.noise.pk with raw binary content.
Using Generated Keys with RZMQ Library:
The RZMQ library's socket options for Noise_XX (NOISE_XX_STATIC_SECRET_KEY, NOISE_XX_REMOTE_STATIC_PUBLIC_KEY) expect raw 32-byte arrays.
--file-format binary, you can read these files directly into a [u8; 32] array in your Rust application.--file-format hex or --file-format base64, your application code will need to read the string from the file and then decode it into raw bytes before setting the socket option.Example: Loading a hex-encoded key in your RZMQ application:
// Assuming you have `hex = "0.4"` in your application's Cargo.toml
use rzmq::{Context, SocketType, ZmqError};
use rzmq::socket::options::NOISE_XX_STATIC_SECRET_KEY; // Import the option constant
use std::fs;
async fn setup_socket_with_hex_key(ctx: &Context, sk_file_path: &str) -> Result<rzmq::Socket, anyhow::Error> {
let socket = ctx.socket(SocketType::Dealer)?; // Or any other type
let sk_hex_str = fs::read_to_string(sk_file_path)?;
let sk_bytes_vec = hex::decode(sk_hex_str.trim())?;
let sk_array: [u8; 32] = sk_bytes_vec.try_into()
.map_err(|_| anyhow::anyhow!("Secret key file content has incorrect length after hex decoding"))?;
socket.set_option_raw(NOISE_XX_STATIC_SECRET_KEY, &sk_array).await?;
// ... set other options like remote public key ...
Ok(socket)
}
Contributions are welcome! Please feel free to open an issue or submit a pull request.
This project is licensed under the Mozilla Public License v2.0 (MPL-2.0). See the LICENSE file for details.