Tahinli/forge
public0 watching
★ 0
| 1 | //! Access tokens: `forge_` + base64url(32 random bytes). Only the sha256 hash is stored. |
| 2 | |
| 3 | use ; |
| 4 | use ; |
| 5 | use ConstantTimeEq; |
| 6 | |
| 7 | /// Fresh random 32 bytes from the thread RNG, a CSPRNG seeded from the OS. It is |
| 8 | /// infallible, so callers need no error path. |
| 9 | pub |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | /// Alphabet for codes typed by people: lowercase letters and digits 2-9, without look-alikes |
| 16 | /// such as `l`, `o`, `0` and `1`. It has exactly 32 symbols, so the low five bits of a random |
| 17 | /// byte pick one uniformly. |
| 18 | pub const READABLE_ALPHABET: & = b"abcdefghijkmnpqrstuvwxyz23456789"; |
| 19 | |
| 20 | /// `len` random characters from [`READABLE_ALPHABET`]. |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | /// Hex-encoded sha256 of the token. |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | /// Constant-time byte comparison. |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 |