diff --git a/src/utils.rs b/src/utils.rs index 105c488..91e1c56 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -10,8 +10,12 @@ pub enum PubkeyDecodeError { /// Accepts any checksum length >=3 pub fn format_pubkey(raw: &str) -> Result { let mut iter = raw.splitn(2, ':'); + let raw_pubkey = iter.next().ok_or(PubkeyDecodeError::BadFormat)?; + if raw_pubkey.len() < 43 || raw_pubkey.len() > 44 { + return Err(PubkeyDecodeError::BadFormat); + } let mut pubkey = [0u8; 32]; - bs58::decode(iter.next().ok_or(PubkeyDecodeError::BadFormat)?) + bs58::decode(raw_pubkey) .into(&mut pubkey) .map_err(|_| PubkeyDecodeError::BadFormat)?;