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
  • Loading branch information
t-nelson authored Jan 18, 2024
1 parent 0e8f2de commit 6dbcdc0
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 6dbcdc0

Please sign in to comment.