pkce_std/check/
chars.rs

1//! Characters used in PKCE code verifiers.
2//!
3//! As per the [standard](https://datatracker.ietf.org/doc/html/rfc7636#section-4.1), code verifiers
4//! consist of alphanumeric characters and the following special characters: `-`, `.`, `_`, and `~`.
5//!
6//! The full character set is `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~`.
7//!
8//! This module provides the [`CHARS`] constant (along with the [`STRING`] constant), which contain
9//! the aforementioned characters.
10
11use const_macros::{const_assert_eq, const_assert_ne};
12
13/// The amount of valid characters in PKCE code verifiers.
14pub const LENGTH: usize = 66;
15
16// constantly assert that the length is non-zero (required for `generate::string` to be safe)
17const_assert_ne!(LENGTH, 0);
18
19/// The characters used in PKCE code verifiers.
20#[rustfmt::skip]
21pub const CHARS: [char; LENGTH] = [
22    // upper
23    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
24    'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
25    'U', 'V', 'W', 'X', 'Y', 'Z',
26    // lower
27    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
28    'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
29    'u', 'v', 'w', 'x', 'y', 'z',
30    // digit
31    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
32    // special
33    '-', '.', '_', '~',
34];
35
36/// The string representation of [`CHARS`].
37pub const STRING: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
38
39const_assert_eq!(STRING.len(), LENGTH);
40
41#[cfg(test)]
42mod tests {
43    use crate::check::{
44        bytes::is_valid,
45        chars::{CHARS, STRING},
46    };
47
48    #[test]
49    fn equality() {
50        let string: String = CHARS.into_iter().collect();
51
52        assert_eq!(string, STRING);
53    }
54
55    #[test]
56    fn validity() {
57        assert!(STRING.bytes().all(is_valid));
58    }
59}