Decode a public key from base32
(s: &str)
| 49 | |
| 50 | /// Decode a public key from base32 |
| 51 | pub fn from_base32(s: &str) -> Result<Self, IdentityError> { |
| 52 | let bytes = data_encoding::BASE32_NOPAD |
| 53 | .decode(s.as_bytes()) |
| 54 | .map_err(|e| IdentityError::InvalidKey(format!("Invalid base32: {}", e)))?; |
| 55 | |
| 56 | if bytes.len() != 32 { |
| 57 | return Err(IdentityError::InvalidKey(format!( |
| 58 | "Expected 32 bytes, got {}", |
| 59 | bytes.len() |
| 60 | ))); |
| 61 | } |
| 62 | |
| 63 | let mut arr = [0u8; 32]; |
| 64 | arr.copy_from_slice(&bytes); |
| 65 | Self::from_bytes(&arr) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | impl fmt::Debug for PublicKey { |