Skip to content

Commit b3503ba

Browse files
committed
Add example to SharedSecret
Currently the rustdoc on `SharedSecret` is wildly incorrect (possibly a cut'n'pasta error). Fix the rustdoc for `SharedSecret` and add an examples section to assist testing the public API. Fixes: 249
1 parent 7a3736a commit b3503ba

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/ecdh.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,23 @@ use key::{SecretKey, PublicKey};
2323
use ffi::{self, CPtr};
2424
use secp256k1_sys::types::{c_int, c_uchar, c_void};
2525

26-
/// A tag used for recovering the public key from a compact signature
26+
/// Enables two parties to create a shared secret without revealing their own secrets.
27+
///
28+
/// # Examples
29+
///
30+
/// ```
31+
/// # #[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))] {
32+
/// # use secp256k1::Secp256k1;
33+
/// # use secp256k1::ecdh::SharedSecret;
34+
/// # use secp256k1::rand::thread_rng;
35+
/// let s = Secp256k1::new();
36+
/// let (sk1, pk1) = s.generate_keypair(&mut thread_rng());
37+
/// let (sk2, pk2) = s.generate_keypair(&mut thread_rng());
38+
/// let sec1 = SharedSecret::new(&pk1, &sk2);
39+
/// let sec2 = SharedSecret::new(&pk2, &sk1);
40+
/// assert_eq!(sec1, sec2);
41+
/// # }
42+
// ```
2743
#[derive(Copy, Clone)]
2844
pub struct SharedSecret {
2945
data: [u8; 256],

0 commit comments

Comments
 (0)