1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::{asn1_string, TestValidCharset};
use crate::{Error, Result};
use alloc::string::String;

asn1_string!(PrintableString);

impl<'a> TestValidCharset for PrintableString<'a> {
    fn test_valid_charset(i: &[u8]) -> Result<()> {
        // Argument must be a reference, because of the .iter().all(F) call below
        #[allow(clippy::trivially_copy_pass_by_ref)]
        fn is_printable(b: &u8) -> bool {
            matches!(*b,
            b'a'..=b'z'
            | b'A'..=b'Z'
            | b'0'..=b'9'
            | b' '
            | b'\''
            | b'('
            | b')'
            | b'+'
            | b','
            | b'-'
            | b'.'
            | b'/'
            | b':'
            | b'='
            | b'?')
        }

        if !i.iter().all(is_printable) {
            return Err(Error::StringInvalidCharset);
        }
        Ok(())
    }
}