Skip to main content

trojan_auth/
lib.rs

1//! Authentication backends for trojan.
2//!
3//! This crate provides authentication backends for the Trojan protocol.
4//!
5//! # Example
6//!
7//! ```
8//! use trojan_auth::{AuthBackend, MemoryAuth, sha224_hex};
9//!
10//! # async fn example() -> Result<(), trojan_auth::AuthError> {
11//! // Create an auth backend from passwords
12//! let auth = MemoryAuth::from_passwords(["my_password"]);
13//!
14//! // Verify a hash
15//! let hash = sha224_hex("my_password");
16//! let result = auth.verify(&hash).await?;
17//! # Ok(())
18//! # }
19//! ```
20//!
21//! # SQL Backend
22//!
23//! Enable the `sql-postgres`, `sql-mysql`, or `sql-sqlite` feature to use
24//! SQL database authentication:
25//!
26//! ```toml
27//! [dependencies]
28//! trojan-auth = { version = "0.1", features = ["sql-postgres"] }
29//! ```
30//!
31//! See the [`sql`] module for more details.
32
33mod error;
34mod hash;
35mod memory;
36mod reloadable;
37mod result;
38mod traits;
39
40// Generic store-based auth (always compiled; only depends on parking_lot + std)
41pub mod store;
42
43// SQL backend (optional feature)
44#[cfg(feature = "sql")]
45pub mod sql;
46
47// HTTP backend (optional feature)
48#[cfg(feature = "http")]
49pub mod http;
50
51// CLI module (optional feature)
52#[cfg(feature = "cli")]
53pub mod cli;
54
55pub use error::AuthError;
56pub use hash::{sha224_hex, verify_password};
57pub use memory::MemoryAuth;
58pub use reloadable::ReloadableAuth;
59pub use result::{AuthMetadata, AuthResult};
60pub use traits::AuthBackend;
61
62#[cfg(feature = "cli")]
63pub use cli::AuthArgs;
64
65// Backward compatibility alias
66#[doc(hidden)]
67pub use memory::HashSetAuth;