Skip to content

Commit

Permalink
sdk: add bounds check when instantiating Keypair from byte array (#…
Browse files Browse the repository at this point in the history
…34817)

(cherry picked from commit 6dbcdc0)
  • Loading branch information
t-nelson authored and mergify[bot] committed Jan 18, 2024
1 parent 35b7df1 commit e18b426
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdk/src/signer/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ impl Keypair {

/// Recovers a `Keypair` from a byte array
pub fn from_bytes(bytes: &[u8]) -> Result<Self, ed25519_dalek::SignatureError> {
if bytes.len() < ed25519_dalek::KEYPAIR_LENGTH {
return Err(ed25519_dalek::SignatureError::from_source(String::from(
"candidate keypair byte array is too short",
)));
}
let secret =
ed25519_dalek::SecretKey::from_bytes(&bytes[..ed25519_dalek::SECRET_KEY_LENGTH])?;
let public =
Expand Down

0 comments on commit e18b426

Please sign in to comment.