Don't panic in `PrivateKey::from_slice`
During upgrade of `secp256k1` a number of function calls needed to be rewritten to not use `from_slice` but `from_byte_array`. Unfortunately, the conversions wasn't correct and caused panics on invalid inputs rather than errors. This fixes it simply by calling `try_into` on the entire slice and converting the error.
This commit is contained in:
parent
6483244280
commit
b87ddc0043
|
@ -466,7 +466,7 @@ impl PrivateKey {
|
||||||
) -> Result<PrivateKey, secp256k1::Error> {
|
) -> Result<PrivateKey, secp256k1::Error> {
|
||||||
Ok(PrivateKey::new(
|
Ok(PrivateKey::new(
|
||||||
secp256k1::SecretKey::from_byte_array(
|
secp256k1::SecretKey::from_byte_array(
|
||||||
data[..32].try_into().expect("Slice should be exactly 32 bytes"),
|
data.try_into().map_err(|_| secp256k1::Error::InvalidSecretKey)?,
|
||||||
)?,
|
)?,
|
||||||
network,
|
network,
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in New Issue