Struct threema_gateway::SecretKey
source · pub struct SecretKey { /* private fields */ }
Expand description
A crypto_box
secret key.
Implementations§
source§impl SecretKey
impl SecretKey
sourcepub fn from_slice(slice: &[u8]) -> Result<SecretKey, TryFromSliceError>
pub fn from_slice(slice: &[u8]) -> Result<SecretKey, TryFromSliceError>
Initialize SecretKey
from a byte slice.
Returns TryFromSliceError
if the slice length is not exactly equal
to KEY_SIZE
.
sourcepub fn generate(csprng: &mut impl CryptoRngCore) -> SecretKey
pub fn generate(csprng: &mut impl CryptoRngCore) -> SecretKey
Generate a random SecretKey
.
sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
sourcepub fn to_bytes(&self) -> [u8; 32]
pub fn to_bytes(&self) -> [u8; 32]
Serialize SecretKey
to bytes.
§⚠️Warning
The serialized bytes are secret key material. Please treat them with the care they deserve!
§Scalar
conversion notes
If you are using the From<Scalar>
impl on SecretKey
(as opposed
to using SecretKey::from_bytes
or one of the other methods that
decodes a secret key from bytes), this method will return the same
value as Scalar::to_bytes
, which may reflect “clamping” if it was
applied to the original Scalar
.
In such cases, it may be undesirable to call this method, since such a
value may not reflect the original scalar prior to clamping. We suggest
you don’t call this method when using From<Scalar>
unless you know
what you’re doing.
Calling SecretKey::to_scalar
can be used to safely round-trip the
scalar value in such cases.
Trait Implementations§
source§impl PartialEq for SecretKey
impl PartialEq for SecretKey
source§impl TryFrom<&[u8]> for SecretKey
impl TryFrom<&[u8]> for SecretKey
§type Error = TryFromSliceError
type Error = TryFromSliceError
impl Eq for SecretKey
Auto Trait Implementations§
impl Freeze for SecretKey
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnwindSafe for SecretKey
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.