pub struct KeyPair<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> {
pub public_key: PublicKey,
pub secret_key: SecretKey,
}Expand description
Public/secret keypair for use with crate::dryocbox::DryocBox and
libsodium-compatible public-key encryption.
Create keypairs with KeyPair::generate, KeyPair::from_seed, or
KeyPair::from_secret_key. There is no new or Default
constructor, so an all-zero secret key is never produced implicitly.
Fields§
§public_key: PublicKeyPublic key
secret_key: SecretKeySecret key
Implementations§
Source§impl KeyPair<Locked<HeapByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>, Locked<HeapByteArray<CRYPTO_BOX_SECRETKEYBYTES>>>
impl KeyPair<Locked<HeapByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>, Locked<HeapByteArray<CRYPTO_BOX_SECRETKEYBYTES>>>
Sourcepub fn generate_locked_keypair() -> Result<Self, Error>
Available on crate feature protected only.
pub fn generate_locked_keypair() -> Result<Self, Error>
protected only.Returns a new randomly generated locked keypair.
§Errors
Returns Error::Io if either allocation cannot be locked,
commonly because the process has reached its locked-memory limit.
§Panics
Panics if either page-aligned allocation cannot be created, its size cannot be represented with guard pages, or the operating system’s random number generator fails.
Sourcepub fn precalculate_locked<OtherPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>(
&self,
third_party_public_key: &OtherPublicKey,
) -> Result<PrecalcSecretKey<Locked<HeapByteArray<CRYPTO_BOX_BEFORENMBYTES>>>, Error>
Available on crate feature protected only.
pub fn precalculate_locked<OtherPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>( &self, third_party_public_key: &OtherPublicKey, ) -> Result<PrecalcSecretKey<Locked<HeapByteArray<CRYPTO_BOX_BEFORENMBYTES>>>, Error>
protected only.Computes a heap-allocated, page-aligned, locked shared secret key
using a secret key from this keypair and
third_party_public_key.
Compatible with libsodium’s crypto_box_beforenm.
§Errors
Returns an error if third_party_public_key is an unacceptable
low-order point or the shared-key allocation cannot be locked.
§Panics
Panics if the page-aligned shared-key allocation cannot be created or its size cannot be represented with guard pages.
Source§impl KeyPair<LockedRO<HeapByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>, LockedRO<HeapByteArray<CRYPTO_BOX_SECRETKEYBYTES>>>
impl KeyPair<LockedRO<HeapByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>, LockedRO<HeapByteArray<CRYPTO_BOX_SECRETKEYBYTES>>>
Sourcepub fn generate_readonly_locked_keypair() -> Result<Self, Error>
Available on crate feature protected only.
pub fn generate_readonly_locked_keypair() -> Result<Self, Error>
protected only.Returns a new randomly generated locked, read-only keypair.
§Errors
Returns Error::Io if either allocation cannot be locked or its
page permissions cannot be changed to read-only.
§Panics
Panics if either page-aligned allocation cannot be created, its size cannot be represented with guard pages, or the operating system’s random number generator fails.
Sourcepub fn precalculate_readonly_locked<OtherPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>(
&self,
third_party_public_key: &OtherPublicKey,
) -> Result<PrecalcSecretKey<LockedRO<HeapByteArray<CRYPTO_BOX_BEFORENMBYTES>>>, Error>
Available on crate feature protected only.
pub fn precalculate_readonly_locked<OtherPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>( &self, third_party_public_key: &OtherPublicKey, ) -> Result<PrecalcSecretKey<LockedRO<HeapByteArray<CRYPTO_BOX_BEFORENMBYTES>>>, Error>
protected only.Computes a heap-allocated, page-aligned, locked, read-only shared
secret key using a secret key from this keypair and
third_party_public_key.
Compatible with libsodium’s crypto_box_beforenm.
§Errors
Returns an error if third_party_public_key is an unacceptable
low-order point, the shared-key allocation cannot be locked, or its
page permissions cannot be changed to read-only.
§Panics
Panics if the page-aligned shared-key allocation cannot be created or its size cannot be represented with guard pages.
Source§impl<PublicKey: NewByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: NewByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> KeyPair<PublicKey, SecretKey>
impl<PublicKey: NewByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: NewByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> KeyPair<PublicKey, SecretKey>
Sourcepub fn from_secret_key(secret_key: SecretKey) -> Self
pub fn from_secret_key(secret_key: SecretKey) -> Self
Derives the public key for secret_key and returns the complete
keypair, consuming the secret key.
Source§impl<'a, PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + TryFrom<&'a [u8]> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + TryFrom<&'a [u8]> + Zeroize> KeyPair<PublicKey, SecretKey>
impl<'a, PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + TryFrom<&'a [u8]> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + TryFrom<&'a [u8]> + Zeroize> KeyPair<PublicKey, SecretKey>
Sourcepub fn from_slices(
public_key: &'a [u8],
secret_key: &'a [u8],
) -> Result<Self, Error>
pub fn from_slices( public_key: &'a [u8], secret_key: &'a [u8], ) -> Result<Self, Error>
Constructs a new keypair from key slices, consuming them. Does not check validity or authenticity of keypair.
§Errors
Returns an error if either slice does not have the required key length, or if the target key type rejects the key bytes.
Source§impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> KeyPair<PublicKey, SecretKey>
impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> KeyPair<PublicKey, SecretKey>
Sourcepub fn precalculate<OtherPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>(
&self,
third_party_public_key: &OtherPublicKey,
) -> Result<PrecalcSecretKey<StackByteArray<CRYPTO_BOX_BEFORENMBYTES>>, Error>
pub fn precalculate<OtherPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>( &self, third_party_public_key: &OtherPublicKey, ) -> Result<PrecalcSecretKey<StackByteArray<CRYPTO_BOX_BEFORENMBYTES>>, Error>
Computes a stack-allocated shared secret key using a secret key from
this keypair and third_party_public_key.
Compatible with libsodium’s crypto_box_beforenm.
§Errors
Returns an error if third_party_public_key is an unacceptable
low-order point.
Trait Implementations§
Source§impl<PublicKey: Clone + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: Clone + ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> Clone for KeyPair<PublicKey, SecretKey>
impl<PublicKey: Clone + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: Clone + ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> Clone for KeyPair<PublicKey, SecretKey>
Source§impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> Debug for KeyPair<PublicKey, SecretKey>
impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> Debug for KeyPair<PublicKey, SecretKey>
Source§impl<'de, PublicKey, SecretKey> Deserialize<'de> for KeyPair<PublicKey, SecretKey>where
PublicKey: Deserialize<'de> + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize,
SecretKey: Deserialize<'de> + ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize,
Available on crate feature serde only.
impl<'de, PublicKey, SecretKey> Deserialize<'de> for KeyPair<PublicKey, SecretKey>where
PublicKey: Deserialize<'de> + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize,
SecretKey: Deserialize<'de> + ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize,
serde only.Source§fn 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>,
Source§impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> Drop for KeyPair<PublicKey, SecretKey>
impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> Drop for KeyPair<PublicKey, SecretKey>
Source§impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> PartialEq for KeyPair<PublicKey, SecretKey>
impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> PartialEq for KeyPair<PublicKey, SecretKey>
Source§impl<PublicKey, SecretKey> Serialize for KeyPair<PublicKey, SecretKey>
Available on crate feature serde only.
impl<PublicKey, SecretKey> Serialize for KeyPair<PublicKey, SecretKey>
serde only.