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::{
13    OLD_SIGNING_KEYS, OpenError, SIGNING_KEYS, SessionClaims, SigningKeys, new_signing_key,
14};
15pub use signing::Signed;
16
17use ring::rand::{SecureRandom, SystemRandom};
18use sofie_core::{Error, Result};
19
20fn random_bytes<const N: usize>(purpose: &str) -> Result<[u8; N]> {
21    let mut bytes = [0; N];
22    SystemRandom::new().fill(&mut bytes).map_err(|_| {
23        Error::internal_message(format!("the system gave no random bytes for {purpose}"))
24    })?;
25    Ok(bytes)
26}