Struct sapio_secp256k1::ecdh::SharedSecret
source · [−]pub struct SharedSecret(_);
Expand description
Enables two parties to create a shared secret without revealing their own secrets.
Examples
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(&pk2, &sk1);
let sec2 = SharedSecret::new(&pk1, &sk2);
assert_eq!(sec1, sec2);
Implementations
sourceimpl SharedSecret
impl SharedSecret
sourcepub fn display_secret(&self) -> DisplaySecret
pub fn display_secret(&self) -> DisplaySecret
Formats the explicit byte value of the shared secret kept inside the type as a little-endian hexadecimal string using the provided formatter.
This is the only method that outputs the actual shared secret value, and, thus, should be used with extreme caution.
Examples
use secp256k1::ecdh::SharedSecret;
let secret = SharedSecret::new(&pk, &sk);
// Here we explicitly display the secret value:
assert_eq!(
format!("{}", secret.display_secret()),
"cf05ae7da039ddce6d56dd57d3000c6dd91c6f1695eae47e05389f11e2467043"
);
// Also, we can explicitly display with `Debug`:
assert_eq!(
format!("{:?}", secret.display_secret()),
format!("DisplaySecret(\"{}\")", secret.display_secret())
);
sourceimpl SharedSecret
impl SharedSecret
sourcepub fn new(point: &PublicKey, scalar: &SecretKey) -> SharedSecret
pub fn new(point: &PublicKey, scalar: &SecretKey) -> SharedSecret
Creates a new shared secret from a pubkey and secret key.
sourcepub fn secret_bytes(&self) -> [u8; 32]
pub fn secret_bytes(&self) -> [u8; 32]
Returns the shared secret as a byte value.
sourcepub fn from_bytes(bytes: [u8; 32]) -> SharedSecret
pub fn from_bytes(bytes: [u8; 32]) -> SharedSecret
Creates a shared secret from bytes
array.
sourcepub fn from_slice(bytes: &[u8]) -> Result<SharedSecret, Error>
pub fn from_slice(bytes: &[u8]) -> Result<SharedSecret, Error>
Creates a shared secret from bytes
slice.
Trait Implementations
sourceimpl Clone for SharedSecret
impl Clone for SharedSecret
sourcefn clone(&self) -> SharedSecret
fn clone(&self) -> SharedSecret
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for SharedSecret
impl Debug for SharedSecret
sourceimpl<'de> Deserialize<'de> for SharedSecret
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for SharedSecret
serde
only.sourcefn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
sourceimpl FromStr for SharedSecret
impl FromStr for SharedSecret
sourceimpl Hash for SharedSecret
impl Hash for SharedSecret
sourceimpl Ord for SharedSecret
impl Ord for SharedSecret
sourcefn eq(&self, other: &SharedSecret) -> bool
fn eq(&self, other: &SharedSecret) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &SharedSecret) -> bool
fn ne(&self, other: &SharedSecret) -> bool
This method tests for !=
.
sourcefn partial_cmp(&self, other: &SharedSecret) -> Option<Ordering>
fn partial_cmp(&self, other: &SharedSecret) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl Serialize for SharedSecret
Available on crate feature serde
only.
impl Serialize for SharedSecret
serde
only.impl Copy for SharedSecret
impl Eq for SharedSecret
impl StructuralEq for SharedSecret
impl StructuralPartialEq for SharedSecret
Auto Trait Implementations
impl RefUnwindSafe for SharedSecret
impl Send for SharedSecret
impl Sync for SharedSecret
impl Unpin for SharedSecret
impl UnwindSafe for SharedSecret
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more