Decode a public key from base32
(s: &str)
| 91 | |
| 92 | /// Decode a public key from base32 |
| 93 | pub fn from_base32(s: &str) -> Result<Self, IdentityError> { |
| 94 | let bytes = data_encoding::BASE32_NOPAD |
| 95 | .decode(s.as_bytes()) |
| 96 | .map_err(|e| IdentityError::InvalidKey(format!("Invalid base32: {}", e)))?; |
| 97 | |
| 98 | if bytes.len() != 32 { |
| 99 | return Err(IdentityError::InvalidKey(format!( |
| 100 | "Expected 32 bytes, got {}", |
| 101 | bytes.len() |
| 102 | ))); |
| 103 | } |
| 104 | |
| 105 | let mut arr = [0u8; 32]; |
| 106 | arr.copy_from_slice(&bytes); |
| 107 | Self::from_bytes(&arr) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | impl fmt::Debug for PublicKey { |