/rust/registry/src/index.crates.io-1949cf8c6b5b557f/sfv-0.14.0/src/utils.rs
Line | Count | Source |
1 | | use base64::engine; |
2 | | |
3 | | pub(crate) const BASE64: engine::GeneralPurpose = engine::GeneralPurpose::new( |
4 | | &base64::alphabet::STANDARD, |
5 | | engine::GeneralPurposeConfig::new() |
6 | | .with_decode_allow_trailing_bits(true) |
7 | | .with_decode_padding_mode(engine::DecodePaddingMode::Indifferent) |
8 | | .with_encode_padding(true), |
9 | | ); |
10 | | |
11 | 0 | const fn is_tchar(c: u8) -> bool { |
12 | | // See tchar values list in https://tools.ietf.org/html/rfc7230#section-3.2.6 |
13 | 0 | matches!( |
14 | 0 | c, |
15 | | b'!' | b'#' |
16 | | | b'$' |
17 | | | b'%' |
18 | | | b'&' |
19 | | | b'\'' |
20 | | | b'*' |
21 | | | b'+' |
22 | | | b'-' |
23 | | | b'.' |
24 | | | b'^' |
25 | | | b'_' |
26 | | | b'`' |
27 | | | b'|' |
28 | | | b'~' |
29 | 0 | ) || c.is_ascii_alphanumeric() |
30 | 0 | } |
31 | | |
32 | 0 | pub(crate) const fn is_allowed_start_token_char(c: u8) -> bool { |
33 | 0 | c.is_ascii_alphabetic() || c == b'*' |
34 | 0 | } |
35 | | |
36 | 0 | pub(crate) const fn is_allowed_inner_token_char(c: u8) -> bool { |
37 | 0 | is_tchar(c) || c == b':' || c == b'/' |
38 | 0 | } |
39 | | |
40 | 0 | pub(crate) const fn is_allowed_start_key_char(c: u8) -> bool { |
41 | 0 | c.is_ascii_lowercase() || c == b'*' |
42 | 0 | } |
43 | | |
44 | 0 | pub(crate) const fn is_allowed_inner_key_char(c: u8) -> bool { |
45 | 0 | c.is_ascii_lowercase() || c.is_ascii_digit() || matches!(c, b'_' | b'-' | b'*' | b'.') |
46 | 0 | } |