Limit pubkey to 43-44 chars
This commit is contained in:
parent
7962df9ae6
commit
51bd692392
|
@ -10,8 +10,12 @@ pub enum PubkeyDecodeError {
|
||||||
/// Accepts any checksum length >=3
|
/// Accepts any checksum length >=3
|
||||||
pub fn format_pubkey(raw: &str) -> Result<String, PubkeyDecodeError> {
|
pub fn format_pubkey(raw: &str) -> Result<String, PubkeyDecodeError> {
|
||||||
let mut iter = raw.splitn(2, ':');
|
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];
|
let mut pubkey = [0u8; 32];
|
||||||
bs58::decode(iter.next().ok_or(PubkeyDecodeError::BadFormat)?)
|
bs58::decode(raw_pubkey)
|
||||||
.into(&mut pubkey)
|
.into(&mut pubkey)
|
||||||
.map_err(|_| PubkeyDecodeError::BadFormat)?;
|
.map_err(|_| PubkeyDecodeError::BadFormat)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue