Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3cc6ace
poc(config): accumulating validation via tailcall-valid
ssddOnTop Jul 8, 2026
e818da5
refactor: tree-structured architecture with layered dependencies
ssddOnTop Jul 8, 2026
d00d3ae
docs: design plan for pluggable hash algorithms + token-format ergono…
ssddOnTop Jul 8, 2026
dda2237
A0: add sha2, hmac, hex dependencies
ssddOnTop Jul 8, 2026
de1cc8f
A1: rename HashSpec -> Argon2Params (pure rename, no behavior change)
ssddOnTop Jul 8, 2026
c8b7515
A2+A3: HashAlgo enum + multi-algo KeyHasher (Sha256/HmacSha256/Argon2id)
ssddOnTop Jul 8, 2026
91897f7
A4: verify via KeyHasher (dispatch on stored prefix), drop direct arg…
ssddOnTop Jul 8, 2026
ab476cf
A5: default hash algorithm -> Sha256; docs + README updates
ssddOnTop Jul 8, 2026
20e2857
refactor(errors): wrap upstream errors via #[from] instead of stringi…
ssddOnTop Jul 8, 2026
02c5a34
B1: add Separator::Underscore (Stripe/GitHub-style)
ssddOnTop Jul 8, 2026
46259cc
B2: custom + optional environment
ssddOnTop Jul 8, 2026
2a929a5
B3: ChecksumBits newtype - checksum length is now specified in bits
ssddOnTop Jul 8, 2026
a1ebd84
B4: example_key() preview (non-secret, correctly-shaped sample token)
ssddOnTop Jul 8, 2026
1baa4f3
docs: record Part B decisions + document token-format configurability
ssddOnTop Jul 8, 2026
4d70159
Drop example_key() (B4)
ssddOnTop Jul 8, 2026
2105a92
config: derive Debug for HashAlgo (SecureString already redacts the p…
ssddOnTop Jul 8, 2026
80b3c8d
make HmacSha256 the default hash algorithm
ssddOnTop Jul 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/.idea
/.firecrawl
95 changes: 94 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "3"

[workspace.dependencies]
argon2 = "0.5"
argon2 = { version = "0.5", features = ["std"] }
password-hash = "0.5"
subtle = "2.6.1"
getrandom = { version = "0.3", features = ["std"] }
Expand All @@ -18,3 +18,7 @@ secrecy = { version = "0.10.3" }
regex = "1.11"
chrono = { version = "0.4.42", features = [] }
nom = "8.0.0"
tailcall-valid = "0.1.4"
sha2 = "0.10"
hmac = "0.12"
hex = "0.4"
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,36 @@ A secure Rust library for generating and validating API keys with built-in secur
## Features

- **Cryptographically secure** key generation (192-bit entropy)
- **Argon2id hashing** (memory-hard, OWASP recommended)
- **Pluggable hashing** — HMAC-SHA256 (keyed default, needs a pepper), SHA-256
(unkeyed), or Argon2id. Fast hashes are appropriate for high-entropy keys per
NIST SP 800-63B
- **BLAKE3 checksums** (2900x faster DoS protection)
- **Constant-time verification** (prevents timing attacks)
- **Automatic memory zeroing** (protects sensitive data)
- **Key expiration** (time-based access control)
- **Key revocation** (instant access denial via stored hash)
- **Configurable token format** — separator (`-` `_` `/` `~`), custom/optional
environment, and checksum length in bits

## Quick Example

```rust
use api_keys_simplified::{ApiKeyManager, Environment, KeyConfig, HashConfig};

// Generate with checksum (enabled by default - 2900x faster DoS protection)
let manager = ApiKeyManager::init_default_config("myapp_sk")?;
use api_keys_simplified::{ApiKeyManager, ConfigBuilder, Environment, KeyStatus, ExposeSecret};

// Build a validated config. The default hash is keyed HMAC-SHA256, so supply a
// server-side pepper (store it separately from your key database). Checksum is
// enabled by default for 2900x faster DoS protection.
let config = ConfigBuilder::new()
.prefix("myapp_sk")
.pepper(std::env::var("API_KEY_PEPPER")?)
.build()?;
let manager = ApiKeyManager::new(config)?;
let api_key = manager.generate(Environment::production())?;

// Show to user once (they must save it)
println!("API Key: {}", api_key.key().expose_secret());

// Store hash in database (PHC format includes salt)
// Store the self-describing hash string in your database
let hash_data = api_key.expose_hash();
database.save(hash_data.hash());

Expand Down
4 changes: 4 additions & 0 deletions crates/api-keys-simplified/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ secrecy.workspace = true
regex.workspace = true
chrono.workspace = true
nom.workspace = true
tailcall-valid.workspace = true
sha2.workspace = true
hmac.workspace = true
hex.workspace = true

[features]
default = []
Expand Down
Loading
Loading