promocrypt
_
_ __ _ __ ___ _ __ ___ ___ ___ _ __ _ _ _ __ | |_
| '_ \| '__/ _ \| '_ ` _ \ / _ \ / __| '__| | | | '_ \| __|
| |_) | | | (_) | | | | | | (_) | (__| | | |_| | |_) | |_
| .__/|_| \___/|_| |_| |_|\___/ \___|_| \__, | .__/ \__|
|_| |___/|_|
Command-line tool for cryptographically secure promotional code generation and management.
Generate millions of unique, validated promotional codes with machine-binding security, database integration, and flexible output formats.
Table of Contents
- Overview
- Features
- Installation
- Quick Start
- Commands Reference
- Database Integration
- Typed Column Values
- External Commands
- Code Formatting
- Check Position
- Storage Encryption
- History & Generation Log
- Secret Rotation
- Shell Completions
- Environment Variables
- Exit Codes
- Examples
- Building from Source
- Performance
- License
Overview
promocrypt is a high-performance CLI for generating and managing promotional codes. Built on the promocrypt-core cryptographic library, it provides:
- Cryptographic security: Codes are generated using secure algorithms with embedded check digits
- Machine binding:
.pcbinfiles can be locked to specific machines - Database integration: Direct insertion to PostgreSQL and SQLite
- Flexible formatting: Prefixes, suffixes, and separators (e.g.,
PROMO-XXXX-XXXX-2024) - Audit trail: Track generation history, secret rotations, and configuration changes
Features
| Feature | Description |
|---|---|
| Code Generation | Generate single codes or millions in batches |
| Code Validation | Validate codes from CLI, files, or databases |
| Database Insert | PostgreSQL and SQLite with batch insertion |
| Storage Encryption | Encrypt codes at rest (AES-256-SIV) |
| External Commands | Pipe to any script (Python, Node.js, etc.) |
| Output Formats | Plain text, JSON, CSV |
| Shell Completions | Bash, Zsh, Fish, PowerShell |
| Check Position | Configurable check digit placement |
| Code Formatting | Prefix, suffix, separators |
| Secret Rotation | Safely change passwords |
| History Tracking | Audit rotations, masterings, changes |
| Generation Log | Track when/how many codes generated |
| PG Sync | Import/export .pcbin to PostgreSQL |
| Dry-run Mode | Preview without generating |
| Rate Limiting | Control generation speed |
Installation
Quick Install (Recommended)
Install with automatic shell completions:
|
Options:
--version VERSION- Install specific version--install-dir DIR- Custom installation directory--init-system- Initialize system-wide configuration--no-completions- Skip shell completions
Manual Download
Download the latest release for your platform:
# Linux (x86_64)
# macOS (Apple Silicon)
Build from Source
# Clone the repository
# Build release binary
# Install to PATH
Quick Start
1. Create a .pcbin file
# Create a new .pcbin file with default settings
# Create with custom formatting
2. Generate codes
# Generate a single code
# Generate 1000 codes to file
# Generate with database insertion
3. Validate codes
# Validate a single code
# Validate from file
# Validate with quiet mode (only show invalid)
Commands Reference
Global Options
promocrypt [OPTIONS] <COMMAND>
Options:
--bin <PATH> Path to .pcbin file (default: ./promocrypt.pcbin)
--name <NAME> Project name (from config)
--config <PATH> Path to project config file
-s, --select Interactively select project
-J, --json JSON input/output mode (disables interactive prompts)
-C, --color <WHEN> Color output: auto, always, never
-E, --env-file <PATH> Load environment from file
-h, --help Print help
-V, --version Print version
Interactive Mode: When -J (JSON mode) is not enabled, interactive mode is
automatically active. Missing required parameters will be prompted interactively.
This provides a guided experience while keeping all CLI arguments available for
power users and script templates.
create
Create a new .pcbin file.
<NAME> Project )
)
)
)
)
)
)
# Basic
# With formatting
# With storage encryption
info
Show .pcbin file information and statistics.
)
)
)
)
generate
Generate promotional codes.
)
)
)
)
# Format options (override .pcbin config)
# Database options
)
# Typed column values
# External command
)
# Generate to stdout
# Generate to file
# Generate with database
# Dry run
validate
Validate promotional codes. Also supports looking up code data in database.
)
)
# Validate and lookup database row
export
Export codes from database.
)
)
)
)
master
Master .pcbin for a different machine.
)
# Get your machine ID
# Master for another machine
config
View or modify .pcbin configuration. Also encrypt/decrypt the .promocrypt config file.
)
)
)
)
# Encrypt/decrypt config file
Config file encryption:
- Uses machine ID only for encryption (no password in encryption key)
- Password required for authentication (verifies access to .pcbin)
- Encrypted files can only be decrypted on the same machine
rotate
Rotate secret password.
)
history
View, export, or clear history.
)
generation-log
View, export, or clear generation log.
)
pg-import
Import .pcbin file into PostgreSQL.
)
)
)
pg-export
Export .pcbin from PostgreSQL to file.
)
)
)
)
completions
Generate shell completions.
<SHELL> Shell:
Database Integration
PostgreSQL Setup
- Create the table:
(
id SERIAL PRIMARY KEY,
code VARCHAR(50) UNIQUE NOT NULL,
campaign_id INTEGER,
status VARCHAR(20) DEFAULT 'active',
used_at TIMESTAMP,
created_at TIMESTAMP DEFAULT NOW
);
- Generate codes using connection URI:
Or use environment variable:
SQLite Setup
- Create the database:
- Generate codes using connection URI:
Using Configuration File
Database settings can be configured in .promocrypt.toml:
# .promocrypt.toml
= "myproject"
[]
= "postgres://user:pass@localhost/mydb"
= "promo_codes"
Then generate without --db flag:
Typed Column Values
Set column values with proper types during generation:
| Option | Type | Example |
|---|---|---|
--set |
String | --set status=active |
--set-int |
Integer | --set-int campaign_id=123 |
--set-float |
Float | --set-float discount=19.99 |
--set-bool |
Boolean | --set-bool single_use=true |
--set-now |
Timestamp | --set-now created_at |
--set-json |
JSON/JSONB | --set-json meta='{"source":"cli"}' |
--set-null |
NULL | --set-null deleted_at |
Priority: --set-* > --extra > config file
Example:
External Commands
Pipe codes to any external program for custom database insertion:
# Plain text (one code per line)
# JSON lines with extra data
Example Scripts
Bash + psql (PostgreSQL):
#!/bin/bash
while ; do
done
Python + MongoDB:
#!/usr/bin/env python3
=
=
=
Node.js + MySQL:
#!/usr/bin/env node
const mysql = require;
const readline = require;
;
Code Formatting
Prefix and Suffix
# Set during creation (stored in .pcbin)
# Override during generation
# Output: PROMO-A3KF7NP2XM-2024
Separators
# Create with separators at positions 4 and 8
# Output: XXXX-XXXX-XX
Check Position
The check digit position can be configured for security:
| Value | Meaning | Example (10-char) |
|---|---|---|
-1 |
End (default) | XXXXXXXXX[C] |
0 |
Start | [C]XXXXXXXXX |
4 |
Position 4 | XXXX[C]XXXXX |
-3 |
3rd from end | XXXXXXX[C]XX |
Security benefit: Attackers don't know where the check digit is located.
Storage Encryption
Enable storage encryption for codes stored in SQLite (desktop apps):
# Enable during creation
# Toggle on existing .pcbin
Algorithm: AES-256-SIV (deterministic, allows lookups)
History & Generation Log
View History
# View all history
# Export to JSON
# Clear (keep last 10)
View Generation Log
# View log
# View summary
# Export to JSON
Secret Rotation
Safely rotate the secret password:
After rotation:
- All future operations require the new password
- The change is logged in history
Shell Completions
Bash
# Or system-wide:
Zsh
# Add to .zshrc:
fpath=(/.zsh/completions )
&&
Fish
PowerShell
promocrypt completions powershell >> $PROFILE
Environment Variables
| Variable | Description |
|---|---|
PROMOCRYPT_PASSWORD |
Default secret password |
PROMOCRYPT_PROJECT |
Default .pcbin file path |
PROMOCRYPT_CONFIG |
Path to .promocrypt config file |
DATABASE_URL |
Database connection string |
NO_COLOR |
Disable colored output |
Example:
# No need to specify --password or --bin
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Validation failed (some codes invalid) |
| 2 | File/path error |
| 3 | Authentication error (wrong secret/machine) |
| 4 | Database error |
| 5 | Configuration error |
| 6 | External command error |
| 7 | Code not found (lookup) |
Examples
Campaign Launch
# Create a campaign-specific .pcbin
# Generate 100,000 codes to database
Multi-Machine Deployment
# On development machine
# Output: a1b2c3d4e5f6...
# Get production server's machine ID
# Output: f6e5d4c3b2a1...
# Master the .pcbin for production
# Copy to production
Bulk Validation
# Validate codes from file
# Validate all codes in database
Export Unused Codes
# Export unused codes to CSV
# Export as SQL for migration
Building from Source
Requirements
- Rust 1.89.0+
- OpenSSL development libraries (Linux)
Supported Platforms
| OS | Architecture | Build Target |
|---|---|---|
| Linux | x86_64 | x86_64-unknown-linux-gnu |
| Linux | ARM64 | aarch64-unknown-linux-gnu |
| macOS | Apple Silicon | aarch64-apple-darwin |
| macOS | Intel | x86_64-apple-darwin |
| Windows | x86_64 | x86_64-pc-windows-msvc |
| Windows | ARM64 | aarch64-pc-windows-msvc |
Build
# Debug build
# Release build
# Run tests
Cross-compilation
# For Linux from macOS
Performance
| Operation | Target |
|---|---|
| Generate 1 code | < 100ms |
| Generate 10K codes | < 2s |
| Generate 1M codes | < 3 min |
| Validate 1 code | < 50ms |
| Validate 10K codes | < 1s |
| DB insert 10K batch | < 5s |
License
MIT License - see LICENSE for details.
Made with Rust