MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / strict_base32

Function strict_base32

atomic-core/src/kg/project_id.rs:14–30  ·  view source on GitHub ↗
(s: &str)

Source from the content-addressed store, hash-verified

12pub struct ProjectIdError;
13
14pub(crate) fn strict_base32(s: &str) -> Result<[u8; 32], ProjectIdError> {
15 if s.len() != 52
16 || !s
17 .bytes()
18 .all(|b| b.is_ascii_uppercase() || (b'2'..=b'7').contains(&b))
19 {
20 return Err(ProjectIdError);
21 }
22 let bytes = data_encoding::BASE32_NOPAD
23 .decode(s.as_bytes())
24 .map_err(|_| ProjectIdError)?;
25 let bytes: [u8; 32] = bytes.try_into().map_err(|_| ProjectIdError)?;
26 if data_encoding::BASE32_NOPAD.encode(&bytes) != s {
27 return Err(ProjectIdError);
28 }
29 Ok(bytes)
30}
31
32impl ProjectId {
33 pub fn generate() -> Self {

Callers 3

parse_identityFunction · 0.85
parse_findingFunction · 0.85
from_base32Method · 0.85

Calls 7

lenMethod · 0.45
allMethod · 0.45
bytesMethod · 0.45
containsMethod · 0.45
decodeMethod · 0.45
as_bytesMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected