Change inline assertions to debug_asserts
All of these were things that are (should be) guaranteed true no matter what input is given to the API, barring unsafe operations on the data.
This commit is contained in:
parent
9e717d4219
commit
96e1844c25
10
src/key.rs
10
src/key.rs
|
@ -128,12 +128,12 @@ impl PublicKey {
|
|||
unsafe {
|
||||
// We can assume the return value because it's not possible to construct
|
||||
// an invalid `SecretKey` without transmute trickery or something
|
||||
assert_eq!(ffi::secp256k1_ec_pubkey_create(
|
||||
secp.ctx,
|
||||
let res = ffi::secp256k1_ec_pubkey_create(secp.ctx,
|
||||
pk.as_mut_ptr(), &mut len,
|
||||
sk.as_ptr(), compressed), 1);
|
||||
sk.as_ptr(), compressed);
|
||||
debug_assert_eq!(res, 1);
|
||||
}
|
||||
assert_eq!(len as usize, pk.len());
|
||||
debug_assert_eq!(len as usize, pk.len());
|
||||
pk
|
||||
}
|
||||
|
||||
|
@ -406,7 +406,7 @@ impl Deserialize for PublicKey {
|
|||
fn visit_seq<V>(&mut self, mut v: V) -> Result<PublicKey, V::Error>
|
||||
where V: de::SeqVisitor
|
||||
{
|
||||
assert!(constants::UNCOMPRESSED_PUBLIC_KEY_SIZE >= constants::COMPRESSED_PUBLIC_KEY_SIZE);
|
||||
debug_assert!(constants::UNCOMPRESSED_PUBLIC_KEY_SIZE >= constants::COMPRESSED_PUBLIC_KEY_SIZE);
|
||||
|
||||
unsafe {
|
||||
use std::mem;
|
||||
|
|
|
@ -56,9 +56,6 @@ pub mod constants;
|
|||
pub mod ffi;
|
||||
pub mod key;
|
||||
|
||||
/// I dunno where else to put this..
|
||||
fn assert_type_is_copy<T: Copy>() { }
|
||||
|
||||
/// A tag used for recovering the public key from a compact signature
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct RecoveryId(i32);
|
||||
|
@ -269,7 +266,7 @@ impl<R: Rng> Secp256k1<R> {
|
|||
return Err(Error::SignFailed);
|
||||
}
|
||||
// This assertation is probably too late :)
|
||||
assert!(len as usize <= constants::MAX_SIGNATURE_SIZE);
|
||||
debug_assert!(len as usize <= constants::MAX_SIGNATURE_SIZE);
|
||||
};
|
||||
Ok(Signature(len as usize, sig))
|
||||
}
|
||||
|
@ -306,7 +303,7 @@ impl<R: Rng> Secp256k1<R> {
|
|||
recid) != 1 {
|
||||
return Err(Error::InvalidSignature);
|
||||
}
|
||||
assert_eq!(len as usize, pk.len());
|
||||
debug_assert_eq!(len as usize, pk.len());
|
||||
};
|
||||
Ok(pk)
|
||||
}
|
||||
|
|
|
@ -116,8 +116,6 @@ macro_rules! impl_array_newtype {
|
|||
fn decode<D: ::serialize::Decoder>(d: &mut D) -> Result<$thing, D::Error> {
|
||||
use serialize::Decodable;
|
||||
|
||||
::assert_type_is_copy::<$ty>();
|
||||
|
||||
d.read_seq(|d, len| {
|
||||
if len != $len {
|
||||
Err(d.error("Invalid length"))
|
||||
|
|
Loading…
Reference in New Issue