Skip to content

Commit 8e701b7

Browse files
committed
Replacing usage of the unsafe blank function to the new function
Signed-off-by: Elichai Turkel <[email protected]>
1 parent 389e1e2 commit 8e701b7

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/ecdh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl SharedSecret {
3030
#[inline]
3131
pub fn new(point: &PublicKey, scalar: &SecretKey) -> SharedSecret {
3232
unsafe {
33-
let mut ss = ffi::SharedSecret::blank();
33+
let mut ss = ffi::SharedSecret::new();
3434
let res = ffi::secp256k1_ecdh(
3535
ffi::secp256k1_context_no_precomp,
3636
&mut ss,

src/key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl PublicKey {
219219
pub fn from_secret_key<C: Signing>(secp: &Secp256k1<C>,
220220
sk: &SecretKey)
221221
-> PublicKey {
222-
let mut pk = unsafe { ffi::PublicKey::blank() };
222+
let mut pk = ffi::PublicKey::new();
223223
unsafe {
224224
// We can assume the return value because it's not possible to construct
225225
// an invalid `SecretKey` without transmute trickery or something
@@ -232,7 +232,7 @@ impl PublicKey {
232232
/// Creates a public key directly from a slice
233233
#[inline]
234234
pub fn from_slice(data: &[u8]) -> Result<PublicKey, Error> {
235-
let mut pk = unsafe { ffi::PublicKey::blank() };
235+
let mut pk = ffi::PublicKey::new();
236236
unsafe {
237237
if ffi::secp256k1_ec_pubkey_parse(
238238
ffi::secp256k1_context_no_precomp,

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl Signature {
246246
#[inline]
247247
/// Converts a DER-encoded byte slice to a signature
248248
pub fn from_der(data: &[u8]) -> Result<Signature, Error> {
249-
let mut ret = unsafe { ffi::Signature::blank() };
249+
let mut ret = ffi::Signature::new();
250250

251251
unsafe {
252252
if ffi::secp256k1_ecdsa_signature_parse_der(
@@ -265,7 +265,7 @@ impl Signature {
265265

266266
/// Converts a 64-byte compact-encoded byte slice to a signature
267267
pub fn from_compact(data: &[u8]) -> Result<Signature, Error> {
268-
let mut ret = unsafe { ffi::Signature::blank() };
268+
let mut ret = ffi::Signature::new();
269269
if data.len() != 64 {
270270
return Err(Error::InvalidSignature)
271271
}
@@ -290,7 +290,7 @@ impl Signature {
290290
/// support serializing to this "format"
291291
pub fn from_der_lax(data: &[u8]) -> Result<Signature, Error> {
292292
unsafe {
293-
let mut ret = ffi::Signature::blank();
293+
let mut ret = ffi::Signature::new();
294294
if ffi::ecdsa_signature_parse_der_lax(
295295
ffi::secp256k1_context_no_precomp,
296296
&mut ret,
@@ -605,7 +605,7 @@ impl<C: Signing> Secp256k1<C> {
605605
pub fn sign(&self, msg: &Message, sk: &key::SecretKey)
606606
-> Signature {
607607

608-
let mut ret = unsafe { ffi::Signature::blank() };
608+
let mut ret = ffi::Signature::new();
609609
unsafe {
610610
// We can assume the return value because it's not possible to construct
611611
// an invalid signature from a valid `Message` and `SecretKey`

src/recovery/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl RecoverableSignature {
5757
/// representation is nonstandard and defined by the libsecp256k1
5858
/// library.
5959
pub fn from_compact(data: &[u8], recid: RecoveryId) -> Result<RecoverableSignature, Error> {
60-
let mut ret = unsafe { ffi::RecoverableSignature::blank() };
60+
let mut ret = ffi::RecoverableSignature::new();
6161

6262
unsafe {
6363
if data.len() != 64 {
@@ -103,7 +103,7 @@ impl RecoverableSignature {
103103
/// for verification
104104
#[inline]
105105
pub fn to_standard(&self) -> Signature {
106-
let mut ret = unsafe { super_ffi::Signature::blank() };
106+
let mut ret = super_ffi::Signature::new();
107107
unsafe {
108108
let err = ffi::secp256k1_ecdsa_recoverable_signature_convert(
109109
super_ffi::secp256k1_context_no_precomp,
@@ -130,7 +130,7 @@ impl<C: Signing> Secp256k1<C> {
130130
pub fn sign_recoverable(&self, msg: &Message, sk: &key::SecretKey)
131131
-> RecoverableSignature {
132132

133-
let mut ret = unsafe { ffi::RecoverableSignature::blank() };
133+
let mut ret = ffi::RecoverableSignature::new();
134134
unsafe {
135135
// We can assume the return value because it's not possible to construct
136136
// an invalid signature from a valid `Message` and `SecretKey`
@@ -157,7 +157,7 @@ impl<C: Verification> Secp256k1<C> {
157157
pub fn recover(&self, msg: &Message, sig: &RecoverableSignature)
158158
-> Result<key::PublicKey, Error> {
159159

160-
let mut pk = unsafe { super_ffi::PublicKey::blank() };
160+
let mut pk = super_ffi::PublicKey::new();
161161

162162
unsafe {
163163
if ffi::secp256k1_ecdsa_recover(self.ctx, &mut pk,

0 commit comments

Comments
 (0)