Skip to content

Commit

Permalink
Merge #391: Add example to SharedSecret
Browse files Browse the repository at this point in the history
b3503ba Add example to SharedSecret (Tobin Harding)

Pull request description:

  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

ACKs for top commit:
  apoelstra:
    ACK b3503ba

Tree-SHA512: 650092388099bb415c11ea335ca6b64c90094f1a51ceecc403911316ee62da0279488af6fa66e00ee5269c129f06d4641085f8ab9be91c98d24a7a4449d235c2
  • Loading branch information
apoelstra committed Feb 4, 2022
2 parents 86447ee + b3503ba commit ecb6261
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,23 @@ use key::{SecretKey, PublicKey};
use ffi::{self, CPtr};
use secp256k1_sys::types::{c_int, c_uchar, c_void};

/// A tag used for recovering the public key from a compact signature
/// Enables two parties to create a shared secret without revealing their own secrets.
///
/// # Examples
///
/// ```
/// # #[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))] {
/// # use secp256k1::Secp256k1;
/// # use secp256k1::ecdh::SharedSecret;
/// # use secp256k1::rand::thread_rng;
/// let s = Secp256k1::new();
/// let (sk1, pk1) = s.generate_keypair(&mut thread_rng());
/// let (sk2, pk2) = s.generate_keypair(&mut thread_rng());
/// let sec1 = SharedSecret::new(&pk1, &sk2);
/// let sec2 = SharedSecret::new(&pk2, &sk1);
/// assert_eq!(sec1, sec2);
/// # }
// ```
#[derive(Copy, Clone)]
pub struct SharedSecret {
data: [u8; 256],
Expand Down

0 comments on commit ecb6261

Please sign in to comment.