Explicit checks for empty slices
This commit is contained in:
parent
b7e20c5b12
commit
ddb8e4fdf2
|
@ -232,6 +232,8 @@ impl PublicKey {
|
|||
/// Creates a public key directly from a slice
|
||||
#[inline]
|
||||
pub fn from_slice(data: &[u8]) -> Result<PublicKey, Error> {
|
||||
if data.is_empty() {return Err(Error::InvalidPublicKey);}
|
||||
|
||||
let mut pk = ffi::PublicKey::new();
|
||||
unsafe {
|
||||
if ffi::secp256k1_ec_pubkey_parse(
|
||||
|
|
|
@ -247,6 +247,8 @@ impl Signature {
|
|||
#[inline]
|
||||
/// Converts a DER-encoded byte slice to a signature
|
||||
pub fn from_der(data: &[u8]) -> Result<Signature, Error> {
|
||||
if data.is_empty() {return Err(Error::InvalidSignature);}
|
||||
|
||||
let mut ret = ffi::Signature::new();
|
||||
|
||||
unsafe {
|
||||
|
@ -290,6 +292,8 @@ impl Signature {
|
|||
/// 2016. It should never be used in new applications. This library does not
|
||||
/// support serializing to this "format"
|
||||
pub fn from_der_lax(data: &[u8]) -> Result<Signature, Error> {
|
||||
if data.is_empty() {return Err(Error::InvalidSignature);}
|
||||
|
||||
unsafe {
|
||||
let mut ret = ffi::Signature::new();
|
||||
if ffi::ecdsa_signature_parse_der_lax(
|
||||
|
|
|
@ -58,6 +58,8 @@ impl RecoverableSignature {
|
|||
/// representation is nonstandard and defined by the libsecp256k1
|
||||
/// library.
|
||||
pub fn from_compact(data: &[u8], recid: RecoveryId) -> Result<RecoverableSignature, Error> {
|
||||
if data.is_empty() {return Err(Error::InvalidSignature);}
|
||||
|
||||
let mut ret = ffi::RecoverableSignature::new();
|
||||
|
||||
unsafe {
|
||||
|
|
Loading…
Reference in New Issue