asn1_rs/asn1_types/strings/
numericstring.rs

1use crate::{asn1_string, TestValidCharset};
2use crate::{Error, Result};
3#[cfg(not(feature = "std"))]
4use alloc::string::String;
5
6asn1_string!(NumericString);
7
8impl<'a> TestValidCharset for NumericString<'a> {
9    fn test_valid_charset(i: &[u8]) -> Result<()> {
10        #[allow(clippy::trivially_copy_pass_by_ref)]
11        fn is_numeric(b: &u8) -> bool {
12            matches!(*b, b'0'..=b'9' | b' ')
13        }
14        if !i.iter().all(is_numeric) {
15            return Err(Error::StringInvalidCharset);
16        }
17        Ok(())
18    }
19}