Skip to content

Commit 8ea2604

Browse files
committed
Deprecate ElligatorSwiftParty in favor of Party
1 parent 33fda15 commit 8ea2604

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

src/ellswift.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl ElligatorSwift {
153153
/// ```
154154
/// # #[cfg(feature = "alloc")] {
155155
/// use secp256k1::{
156-
/// ellswift::{ElligatorSwift, ElligatorSwiftParty},
156+
/// ellswift::{ElligatorSwift, Party},
157157
/// PublicKey, SecretKey, XOnlyPublicKey, Secp256k1,
158158
/// };
159159
/// use core::str::FromStr;
@@ -166,8 +166,8 @@ impl ElligatorSwift {
166166
/// let alice_es = ElligatorSwift::from_seckey(&secp, alice_sk, None);
167167
/// let bob_es = ElligatorSwift::from_seckey(&secp, bob_sk, None);
168168
///
169-
/// let alice_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, alice_sk, ElligatorSwiftParty::A, None);
170-
/// let bob_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, bob_sk, ElligatorSwiftParty::B, None);
169+
/// let alice_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, alice_sk, Party::Initiator, None);
170+
/// let bob_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, bob_sk, Party::Responder, None);
171171
///
172172
/// assert_eq!(alice_shared_secret, bob_shared_secret);
173173
/// # }
@@ -176,18 +176,19 @@ impl ElligatorSwift {
176176
ellswift_a: ElligatorSwift,
177177
ellswift_b: ElligatorSwift,
178178
secret_key: SecretKey,
179-
party: ElligatorSwiftParty,
179+
party: impl Into<Party>,
180180
data: Option<&[u8]>,
181181
) -> ElligatorSwiftSharedSecret {
182182
let mut shared_secret = [0u8; 32];
183+
let p: Party = party.into();
183184
unsafe {
184185
let ret = ffi::secp256k1_ellswift_xdh(
185186
ffi::secp256k1_context_no_precomp,
186187
shared_secret.as_mut_c_ptr(),
187188
ellswift_a.as_c_ptr(),
188189
ellswift_b.as_c_ptr(),
189190
secret_key.as_c_ptr(),
190-
party.to_ffi_int(),
191+
p.to_ffi_int(),
191192
ffi::secp256k1_ellswift_xdh_hash_function_bip324,
192193
data.as_c_ptr() as *mut c_void,
193194
);
@@ -205,22 +206,23 @@ impl ElligatorSwift {
205206
ellswift_a: ElligatorSwift,
206207
ellswift_b: ElligatorSwift,
207208
secret_key: SecretKey,
208-
party: ElligatorSwiftParty,
209+
party: impl Into<Party>,
209210
mut hash_function: F,
210211
) -> ElligatorSwiftSharedSecret
211212
where
212213
F: FnMut([u8; 32], [u8; 64], [u8; 64]) -> ElligatorSwiftSharedSecret,
213214
{
214215
let mut shared_secret = [0u8; 32];
215216
let hashfp = hash_callback::<F>;
217+
let p: Party = party.into();
216218
unsafe {
217219
let ret = ffi::secp256k1_ellswift_xdh(
218220
ffi::secp256k1_context_no_precomp,
219221
shared_secret.as_mut_c_ptr(),
220222
ellswift_a.0.as_c_ptr(),
221223
ellswift_b.0.as_c_ptr(),
222224
secret_key.as_c_ptr(),
223-
party.to_ffi_int(),
225+
p.to_ffi_int(),
224226
Some(hashfp),
225227
&mut hash_function as *mut F as *mut c_void,
226228
);
@@ -285,22 +287,14 @@ impl ElligatorSwiftSharedSecret {
285287
/// we are. In this context, "we" means the party that is using this library, and possesses the
286288
/// secret key passed to `ElligatorSwift::shared_secret`.
287289
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
290+
#[deprecated(since = "0.30.0", note = "Use `Party` instead.")]
288291
pub enum ElligatorSwiftParty {
289292
/// We are the initiator of the ECDH
290293
A,
291294
/// We are the responder of the ECDH
292295
B,
293296
}
294297

295-
impl ElligatorSwiftParty {
296-
fn to_ffi_int(self) -> c_int {
297-
match self {
298-
ElligatorSwiftParty::A => 0,
299-
ElligatorSwiftParty::B => 1,
300-
}
301-
}
302-
}
303-
304298
/// Represents the two parties in ECDH
305299
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
306300
pub enum Party {
@@ -310,6 +304,7 @@ pub enum Party {
310304
Responder,
311305
}
312306

307+
#[allow(deprecated)]
313308
impl From<ElligatorSwiftParty> for Party {
314309
fn from(value: ElligatorSwiftParty) -> Self {
315310
match value {
@@ -366,7 +361,7 @@ mod tests {
366361

367362
use crate::ellswift::ElligatorSwift;
368363
#[cfg(all(not(secp256k1_fuzz), feature = "alloc"))]
369-
use crate::ellswift::{ElligatorSwiftParty, ElligatorSwiftSharedSecret};
364+
use crate::ellswift::{ElligatorSwiftSharedSecret, Party};
370365
#[cfg(all(not(secp256k1_fuzz), feature = "alloc"))]
371366
use crate::SecretKey;
372367
use crate::{from_hex, PublicKey, XOnlyPublicKey};
@@ -412,7 +407,7 @@ mod tests {
412407
ell,
413408
ell,
414409
SecretKey::from_slice(&priv32).unwrap(),
415-
ElligatorSwiftParty::A,
410+
Party::Initiator,
416411
|_, _, _| ElligatorSwiftSharedSecret([0xff; 32]),
417412
);
418413
assert_eq!(pk, ElligatorSwiftSharedSecret([0xff; 32]));
@@ -626,8 +621,7 @@ mod tests {
626621
)
627622
};
628623
let sec_key = SecretKey::from_slice(&my_secret).unwrap();
629-
let initiator =
630-
if initiator == 0 { ElligatorSwiftParty::B } else { ElligatorSwiftParty::A };
624+
let initiator = if initiator == 0 { Party::Responder } else { Party::Initiator };
631625

632626
let shared = ElligatorSwift::shared_secret(el_a, el_b, sec_key, initiator, None);
633627

0 commit comments

Comments
 (0)