Replacing usage of the unsafe `blank` function to the `new` function
Signed-off-by: Elichai Turkel <elichai.turkel@gmail.com>
This commit is contained in:
parent
389e1e2449
commit
8e701b75b2
|
@ -30,7 +30,7 @@ impl SharedSecret {
|
|||
#[inline]
|
||||
pub fn new(point: &PublicKey, scalar: &SecretKey) -> SharedSecret {
|
||||
unsafe {
|
||||
let mut ss = ffi::SharedSecret::blank();
|
||||
let mut ss = ffi::SharedSecret::new();
|
||||
let res = ffi::secp256k1_ecdh(
|
||||
ffi::secp256k1_context_no_precomp,
|
||||
&mut ss,
|
||||
|
|
|
@ -219,7 +219,7 @@ impl PublicKey {
|
|||
pub fn from_secret_key<C: Signing>(secp: &Secp256k1<C>,
|
||||
sk: &SecretKey)
|
||||
-> PublicKey {
|
||||
let mut pk = unsafe { ffi::PublicKey::blank() };
|
||||
let mut pk = ffi::PublicKey::new();
|
||||
unsafe {
|
||||
// We can assume the return value because it's not possible to construct
|
||||
// an invalid `SecretKey` without transmute trickery or something
|
||||
|
@ -232,7 +232,7 @@ impl PublicKey {
|
|||
/// Creates a public key directly from a slice
|
||||
#[inline]
|
||||
pub fn from_slice(data: &[u8]) -> Result<PublicKey, Error> {
|
||||
let mut pk = unsafe { ffi::PublicKey::blank() };
|
||||
let mut pk = ffi::PublicKey::new();
|
||||
unsafe {
|
||||
if ffi::secp256k1_ec_pubkey_parse(
|
||||
ffi::secp256k1_context_no_precomp,
|
||||
|
|
|
@ -246,7 +246,7 @@ impl Signature {
|
|||
#[inline]
|
||||
/// Converts a DER-encoded byte slice to a signature
|
||||
pub fn from_der(data: &[u8]) -> Result<Signature, Error> {
|
||||
let mut ret = unsafe { ffi::Signature::blank() };
|
||||
let mut ret = ffi::Signature::new();
|
||||
|
||||
unsafe {
|
||||
if ffi::secp256k1_ecdsa_signature_parse_der(
|
||||
|
@ -265,7 +265,7 @@ impl Signature {
|
|||
|
||||
/// Converts a 64-byte compact-encoded byte slice to a signature
|
||||
pub fn from_compact(data: &[u8]) -> Result<Signature, Error> {
|
||||
let mut ret = unsafe { ffi::Signature::blank() };
|
||||
let mut ret = ffi::Signature::new();
|
||||
if data.len() != 64 {
|
||||
return Err(Error::InvalidSignature)
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ impl Signature {
|
|||
/// support serializing to this "format"
|
||||
pub fn from_der_lax(data: &[u8]) -> Result<Signature, Error> {
|
||||
unsafe {
|
||||
let mut ret = ffi::Signature::blank();
|
||||
let mut ret = ffi::Signature::new();
|
||||
if ffi::ecdsa_signature_parse_der_lax(
|
||||
ffi::secp256k1_context_no_precomp,
|
||||
&mut ret,
|
||||
|
@ -605,7 +605,7 @@ impl<C: Signing> Secp256k1<C> {
|
|||
pub fn sign(&self, msg: &Message, sk: &key::SecretKey)
|
||||
-> Signature {
|
||||
|
||||
let mut ret = unsafe { ffi::Signature::blank() };
|
||||
let mut ret = ffi::Signature::new();
|
||||
unsafe {
|
||||
// We can assume the return value because it's not possible to construct
|
||||
// an invalid signature from a valid `Message` and `SecretKey`
|
||||
|
|
|
@ -57,7 +57,7 @@ impl RecoverableSignature {
|
|||
/// representation is nonstandard and defined by the libsecp256k1
|
||||
/// library.
|
||||
pub fn from_compact(data: &[u8], recid: RecoveryId) -> Result<RecoverableSignature, Error> {
|
||||
let mut ret = unsafe { ffi::RecoverableSignature::blank() };
|
||||
let mut ret = ffi::RecoverableSignature::new();
|
||||
|
||||
unsafe {
|
||||
if data.len() != 64 {
|
||||
|
@ -103,7 +103,7 @@ impl RecoverableSignature {
|
|||
/// for verification
|
||||
#[inline]
|
||||
pub fn to_standard(&self) -> Signature {
|
||||
let mut ret = unsafe { super_ffi::Signature::blank() };
|
||||
let mut ret = super_ffi::Signature::new();
|
||||
unsafe {
|
||||
let err = ffi::secp256k1_ecdsa_recoverable_signature_convert(
|
||||
super_ffi::secp256k1_context_no_precomp,
|
||||
|
@ -130,7 +130,7 @@ impl<C: Signing> Secp256k1<C> {
|
|||
pub fn sign_recoverable(&self, msg: &Message, sk: &key::SecretKey)
|
||||
-> RecoverableSignature {
|
||||
|
||||
let mut ret = unsafe { ffi::RecoverableSignature::blank() };
|
||||
let mut ret = ffi::RecoverableSignature::new();
|
||||
unsafe {
|
||||
// We can assume the return value because it's not possible to construct
|
||||
// an invalid signature from a valid `Message` and `SecretKey`
|
||||
|
@ -157,7 +157,7 @@ impl<C: Verification> Secp256k1<C> {
|
|||
pub fn recover(&self, msg: &Message, sig: &RecoverableSignature)
|
||||
-> Result<key::PublicKey, Error> {
|
||||
|
||||
let mut pk = unsafe { super_ffi::PublicKey::blank() };
|
||||
let mut pk = super_ffi::PublicKey::new();
|
||||
|
||||
unsafe {
|
||||
if ffi::secp256k1_ecdsa_recover(self.ctx, &mut pk,
|
||||
|
|
Loading…
Reference in New Issue