Skip to main content

sofie_auth/
lib.rs

1//! Signing and sealing: sessions sealed into a cookie with no server store, signed links and tokens.
2
3mod bearer;
4mod digest;
5mod principal_token;
6mod session;
7mod signing;
8
9pub use bearer::BearerToken;
10pub use digest::digest;
11pub use principal_token::{Acting, TokenRefused};
12pub use session::{OLD_SIGNING_KEYS, OpenError, SIGNING_KEYS, SessionClaims, SigningKeys};
13pub use signing::Signed;
14
15use ring::rand::{SecureRandom, SystemRandom};
16use sofie_core::{Error, Result};
17
18fn random_bytes<const N: usize>(purpose: &str) -> Result<[u8; N]> {
19    let mut bytes = [0; N];
20    SystemRandom::new().fill(&mut bytes).map_err(|_| {
21        Error::internal_message(format!("the system gave no random bytes for {purpose}"))
22    })?;
23    Ok(bytes)
24}