Skip to main content

aster_forge_crypto/
lib.rs

1//! Shared cryptographic helpers for Aster services.
2//!
3//! The crate currently exposes password hashing and digest utilities that were duplicated across
4//! application code. It keeps the error surface narrow so services can map cryptographic failures
5//! into their own API or domain errors without depending on implementation-specific error types.
6#![deny(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
7#![cfg_attr(
8    not(test),
9    deny(
10        clippy::unwrap_used,
11        clippy::unreachable,
12        clippy::expect_used,
13        clippy::panic,
14        clippy::unimplemented,
15        clippy::todo
16    )
17)]
18
19pub mod hash;
20
21pub use hash::{
22    bytes_to_hex, hash_password, new_sha256, sha256_digest_to_hex, sha256_hex, verify_password,
23};
24
25/// Result type returned by `aster_forge_crypto` helpers.
26pub type Result<T> = std::result::Result<T, CryptoError>;
27
28/// Errors produced by cryptographic helper functions.
29#[derive(Debug, thiserror::Error)]
30pub enum CryptoError {
31    /// Password hashing, parsing, or verification failed.
32    #[error("password hash error: {0}")]
33    PasswordHash(String),
34}
35
36impl CryptoError {
37    /// Creates a password-hash error from any displayable error value.
38    pub fn password_hash(error: impl std::fmt::Display) -> Self {
39        Self::PasswordHash(error.to_string())
40    }
41}