pub struct SecretKey(_);
Expand description
A secret key; wraps a single prime field element. The field element is
heap allocated to avoid any stack copying that result when passing
SecretKey
s between stack frames.
Serde integration
SecretKey
implements Deserialize
but not Serialize
to avoid accidental
serialization in insecure contexts. To enable both use the ::serde_impl::SerdeSecret
wrapper which implements both Deserialize
and Serialize
.
Implementations
sourceimpl SecretKey
impl SecretKey
sourcepub fn from_mut(fr: &mut Fr) -> Self
pub fn from_mut(fr: &mut Fr) -> Self
Creates a new SecretKey
from a mutable reference to a field element. This constructor
takes a reference to avoid any unnecessary stack copying/moving of secrets (i.e. the field
element). The field element is copied bytewise onto the heap, the resulting Box
is
stored in the returned SecretKey
.
WARNING this constructor will overwrite the referenced Fr
element with zeros after it
has been copied onto the heap.
sourcepub fn random() -> Self
pub fn random() -> Self
Creates a new random instance of SecretKey
.
If you want to use/define your own random number generator, you should use the constructor:
SecretKey::sample()
. If you do not
need to specify your own RNG, you should use the
SecretKey::random()
constructor, which uses
rand::thread_rng()
internally as its
RNG.
sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
Returns the matching public key.
sourcepub fn decrypt(&self, ct: &Ciphertext) -> Option<Vec<u8>>
pub fn decrypt(&self, ct: &Ciphertext) -> Option<Vec<u8>>
Returns the decrypted text, or None
, if the ciphertext isn’t valid.
sourcepub fn reveal(&self) -> String
pub fn reveal(&self) -> String
Generates a non-redacted debug string. This method differs from
the Debug
implementation in that it does leak the secret prime
field element.
sourcepub fn derive_child(&self, index: &[u8]) -> Self
pub fn derive_child(&self, index: &[u8]) -> Self
Derives a child secret key for a given index.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for SecretKey
impl<'de> Deserialize<'de> for SecretKey
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Distribution<SecretKey> for Standard
impl Distribution<SecretKey> for Standard
sourcefn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> SecretKey
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> SecretKey
Creates a new random instance of SecretKey
. If you do not need to specify your own RNG,
you should use the SecretKey::random()
constructor,
which uses rand::thread_rng()
internally as its RNG.
sourcefn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T> where
R: Rng,
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T> where
R: Rng,
Create an iterator that generates random values of T
, using rng
as
the source of randomness. Read more
impl Eq for SecretKey
impl StructuralEq for SecretKey
impl StructuralPartialEq for SecretKey
Auto Trait Implementations
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnwindSafe for SecretKey
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub 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.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more