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