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