Skip to content

Commit

Permalink
Merge pull request #296 from sanket1729/seckey_fromstr
Browse files Browse the repository at this point in the history
Fix SecretKey FromStr bug
  • Loading branch information
elichai authored Apr 29, 2021
2 parents b48d1ea + 6265b25 commit a66f581
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl str::FromStr for SecretKey {
fn from_str(s: &str) -> Result<SecretKey, Error> {
let mut res = [0; constants::SECRET_KEY_SIZE];
match from_hex(s, &mut res) {
Ok(constants::SECRET_KEY_SIZE) => Ok(SecretKey(res)),
Ok(constants::SECRET_KEY_SIZE) => SecretKey::from_slice(&res),
_ => Err(Error::InvalidSecretKey)
}
}
Expand Down Expand Up @@ -525,6 +525,10 @@ mod test {
fn invalid_secret_key() {
// Zero
assert_eq!(SecretKey::from_slice(&[0; 32]), Err(InvalidSecretKey));
assert_eq!(
SecretKey::from_str(&format!("0000000000000000000000000000000000000000000000000000000000000000")),
Err(InvalidSecretKey)
);
// -1
assert_eq!(SecretKey::from_slice(&[0xff; 32]), Err(InvalidSecretKey));
// Top of range
Expand Down

0 comments on commit a66f581

Please sign in to comment.