pub struct SecretKey { /* private fields */ }
Expand description
A crypto_box
secret key.
Implementations§
source§impl SecretKey
impl SecretKey
sourcepub fn from_bytes(bytes: [u8; 32]) -> Self
pub fn from_bytes(bytes: [u8; 32]) -> Self
Initialize SecretKey
from a byte array.
sourcepub fn from_slice(slice: &[u8]) -> Result<Self, TryFromSliceError>
pub fn from_slice(slice: &[u8]) -> Result<Self, 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) -> Self
pub fn generate(csprng: &mut impl CryptoRngCore) -> Self
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 TryFrom<&[u8]> for SecretKey
impl TryFrom<&[u8]> for SecretKey
source§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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)