weirdnet_accounts/lib.rs
1//! Account building blocks shared by WeirdBrains services (TAUR, Salty Gull).
2//!
3//! Storage stays with the application: this crate holds the rules and the cryptography,
4//! and never opens a database.
5//!
6//! - [`password`]: Argon2id hashing (PHC strings) and the minimum-length rule.
7//! - [`token`]: 256-bit random tokens handed out once; only their SHA-256 is stored.
8//! - [`names`]: user-name and email checks.
9//! - [`ratelimit`]: fixed-window per-client limits, generic over the app's request classes,
10//! with `X-Forwarded-For` honoured only from trusted proxies.
11//! - [`apikeys`]: org-scoped API keys with a visible prefix, scopes, optional app and channel
12//! bindings, expiry and revocation.
13#![forbid(unsafe_code)]
14#![warn(missing_docs)]
15
16pub mod apikeys;
17pub mod error;
18pub mod names;
19pub mod password;
20pub mod ratelimit;
21pub mod token;
22
23pub use error::{Error, Result};
24
25/// Seconds since the Unix epoch (0 if the clock is before 1970).
26pub fn now() -> i64 {
27 std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_secs() as i64).unwrap_or(0)
28}
29
30pub(crate) fn hex(bytes: &[u8]) -> String {
31 bytes.iter().map(|b| format!("{b:02x}")).collect()
32}