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

Method from_base32

atomic-identity/src/keypair.rs:51–66  ·  view source on GitHub ↗

Decode a public key from base32

(s: &str)

Source from the content-addressed store, hash-verified

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
69impl fmt::Debug for PublicKey {

Callers

nothing calls this directly

Calls 3

decodeMethod · 0.80
as_bytesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected