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// SQL backend (optional feature)
41#[cfg(feature = "sql")]
42pub mod sql;
43
44// CLI module (optional feature)
45#[cfg(feature = "cli")]
46pub mod cli;
47
48pub use error::AuthError;
49pub use hash::{sha224_hex, verify_password};
50pub use memory::MemoryAuth;
51pub use reloadable::ReloadableAuth;
52pub use result::{AuthMetadata, AuthResult};
53pub use traits::AuthBackend;
54
55#[cfg(feature = "cli")]
56pub use cli::AuthArgs;
57
58// Backward compatibility alias
59#[doc(hidden)]
60pub use memory::HashSetAuth;