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

Method from_base32

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

Decode a public key from base32

(s: &str)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

decodeMethod · 0.45
as_bytesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected