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

Method from_base32

atomic-identity/src/identity.rs:71–86  ·  view source on GitHub ↗

Decode an identity ID from base32.

(s: &str)

Source from the content-addressed store, hash-verified

69
70 /// Decode an identity ID from base32.
71 pub fn from_base32(s: &str) -> Result<Self, IdentityError> {
72 let bytes = data_encoding::BASE32_NOPAD
73 .decode(s.as_bytes())
74 .map_err(|_| IdentityError::InvalidBase32)?;
75
76 if bytes.len() != 32 {
77 return Err(IdentityError::InvalidKey(format!(
78 "Expected 32 bytes, got {}",
79 bytes.len()
80 )));
81 }
82
83 let mut arr = [0u8; 32];
84 arr.copy_from_slice(&bytes);
85 Ok(IdentityId(arr))
86 }
87
88 /// Get a short form of the ID for display (first 8 characters).
89 pub fn short(&self) -> String {

Callers

nothing calls this directly

Calls 4

IdentityIdClass · 0.85
decodeMethod · 0.80
as_bytesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected