1#![doc = include_str!("../README.md")]
2#![allow(clippy::new_without_default)]
3
4use rand::rngs::OsRng;
5use rand::RngCore;
6
7#[cfg(feature = "b64")]
9use std::str::FromStr;
10
11#[cfg(feature = "cipher")]
12pub mod cipher;
13
14#[cfg(feature = "signature")]
15pub mod signature;
16
17#[cfg(feature = "hash")]
18pub mod hash;
19
20pub mod token;
21
22pub mod error;
23
24pub fn xor(buf: &mut [u8], key: &[u8]) {
30 assert_eq!(buf.len(), key.len());
31
32 for (a, b) in buf.iter_mut().zip(key) {
33 *a ^= *b;
34 }
35}
36
37pub fn fill_random(buf: &mut [u8]) {
39 OsRng.fill_bytes(buf)
40}
41
42#[inline(always)]
48const fn calculate_b64_len(s: usize) -> usize {
49 let s = 4 * s;
50
51 let mut d = s / 3;
53 let r = s % 3;
54 if r > 0 {
55 d += 1;
56 }
57
58 d
59}