Decode an identity ID from base32.
(s: &str)
| 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 { |
nothing calls this directly
no test coverage detected