Merge pull request #296 from sanket1729/seckey_fromstr
Fix SecretKey FromStr bug
This commit is contained in:
commit
a66f581b36
|
@ -51,7 +51,7 @@ impl str::FromStr for SecretKey {
|
||||||
fn from_str(s: &str) -> Result<SecretKey, Error> {
|
fn from_str(s: &str) -> Result<SecretKey, Error> {
|
||||||
let mut res = [0; constants::SECRET_KEY_SIZE];
|
let mut res = [0; constants::SECRET_KEY_SIZE];
|
||||||
match from_hex(s, &mut res) {
|
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)
|
_ => Err(Error::InvalidSecretKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -525,6 +525,10 @@ mod test {
|
||||||
fn invalid_secret_key() {
|
fn invalid_secret_key() {
|
||||||
// Zero
|
// Zero
|
||||||
assert_eq!(SecretKey::from_slice(&[0; 32]), Err(InvalidSecretKey));
|
assert_eq!(SecretKey::from_slice(&[0; 32]), Err(InvalidSecretKey));
|
||||||
|
assert_eq!(
|
||||||
|
SecretKey::from_str(&format!("0000000000000000000000000000000000000000000000000000000000000000")),
|
||||||
|
Err(InvalidSecretKey)
|
||||||
|
);
|
||||||
// -1
|
// -1
|
||||||
assert_eq!(SecretKey::from_slice(&[0xff; 32]), Err(InvalidSecretKey));
|
assert_eq!(SecretKey::from_slice(&[0xff; 32]), Err(InvalidSecretKey));
|
||||||
// Top of range
|
// Top of range
|
||||||
|
|
Loading…
Reference in New Issue