From c0decd0cd110abbdbd5e3c6a332927682c395d63 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Sun, 6 Oct 2024 21:42:47 +0400 Subject: [PATCH] avoid changing behaviour of Keypair::from_bytes --- sdk/signer/src/keypair.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sdk/signer/src/keypair.rs b/sdk/signer/src/keypair.rs index 5167666ea03a81..e2aef9608241f3 100644 --- a/sdk/signer/src/keypair.rs +++ b/sdk/signer/src/keypair.rs @@ -38,12 +38,16 @@ impl Keypair { /// Recovers a `Keypair` from a byte array pub fn from_bytes(slice: &[u8]) -> Result { - let Ok(bytes): Result<[u8; 64], _> = slice.try_into() else { - return Err(ed25519_dalek::SignatureError::from_source(String::from( - "candidate keypair byte array is too short", - ))); - }; - Ok(Self(ed25519_dalek::SigningKey::from_keypair_bytes(&bytes)?)) + let arr: [u8; ed25519_dalek::KEYPAIR_LENGTH] = slice + .get(0..ed25519_dalek::KEYPAIR_LENGTH) + .ok_or_else(|| { + ed25519_dalek::SignatureError::from_source(String::from( + "candidate keypair byte array is too short", + )) + })? + .try_into() + .unwrap(); + Ok(Self(ed25519_dalek::SigningKey::from_keypair_bytes(&arr)?)) } /// Returns this `Keypair` as a byte array