Limit pubkey to 43-44 chars

This commit is contained in:
Pascal Engélibert 2020-12-08 21:12:02 +01:00
parent 7962df9ae6
commit 51bd692392
1 changed files with 5 additions and 1 deletions

View File

@ -10,8 +10,12 @@ pub enum PubkeyDecodeError {
/// Accepts any checksum length >=3
pub fn format_pubkey(raw: &str) -> Result<String, PubkeyDecodeError> {
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)?;