Skip to content
Snippets Groups Projects
Commit 8ad244ae authored by Éloïs's avatar Éloïs
Browse files

[fix] ed25519:pubkey min size must applied on keys module

parent 7d6a36b4
No related branches found
No related tags found
1 merge request!255[fix] ed25519:pubkey min size must applied on keys module
......@@ -28,22 +28,17 @@ pub fn str_base58_to_32bytes(base58_data: &str) -> Result<([u8; 32], usize), Bas
debug!("str_base58_to_32bytes({});", base58_data);
match bs58::decode(base58_data).into_vec() {
Ok(result) => {
if result.len() == 32 {
let len = result.len();
if len <= 32 {
let mut u8_array = [0; 32];
u8_array[..32].clone_from_slice(&result[..32]);
u8_array[..len].clone_from_slice(&result[..len]);
Ok((u8_array, 32))
} else if result.len() == 31 {
let mut u8_array = [0; 32];
u8_array[..31].clone_from_slice(&result[..31]);
Ok((u8_array, 31))
Ok((u8_array, len))
} else {
Err(BaseConvertionError::InvalidLength {
expected: 32,
found: result.len(),
found: len,
})
}
}
......
......@@ -214,7 +214,14 @@ impl super::PublicKey for PublicKey {
#[inline]
fn from_base58(base58_data: &str) -> Result<Self, BaseConvertionError> {
let (datas, len) = b58::str_base58_to_32bytes(base58_data)?;
Ok(PublicKey { datas, len })
if len < *PUBKEY_MIN_SIZE_IN_BYTES {
Err(BaseConvertionError::InvalidLength {
expected: *PUBKEY_SIZE_IN_BYTES,
found: len,
})
} else {
Ok(PublicKey { datas, len })
}
}
fn to_bytes_vector(&self) -> Vec<u8> {
......@@ -222,7 +229,7 @@ impl super::PublicKey for PublicKey {
}
fn verify(&self, message: &[u8], signature: &Self::Signature) -> Result<(), SigError> {
Ok(UnparsedPublicKey::new(&ED25519, self)
Ok(UnparsedPublicKey::new(&ED25519, self.as_ref())
.verify(message, &signature.0)
.map_err(|_| SigError::InvalidSig)?)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment