Struct ed25519::pkcs8::KeypairBytes

source ·
pub struct KeypairBytes {
    pub secret_key: [u8; 32],
    pub public_key: Option<PublicKeyBytes>,
}
Available on crate feature pkcs8 only.
Expand description

Ed25519 keypair serialized as bytes.

This type is primarily useful for decoding/encoding PKCS#8 private key files (either DER or PEM) encoded using the following traits:

PKCS#8 private key files encoded with PEM begin with:

-----BEGIN PRIVATE KEY-----

Note that this type operates on raw bytes and performs no validation that keys represent valid Ed25519 field elements.

Fields§

§secret_key: [u8; 32]

Ed25519 secret key.

Little endian serialization of an element of the Curve25519 scalar field, prior to “clamping” (i.e. setting/clearing bits to ensure the scalar is actually a valid field element)

§public_key: Option<PublicKeyBytes>

Ed25519 public key (if available).

Compressed Edwards-y encoded curve point.

Implementations§

source§

impl KeypairBytes

source

pub fn from_bytes(bytes: &[u8; 64]) -> Self

Parse raw keypair from a 64-byte input.

source

pub fn to_bytes(&self) -> Option<[u8; 64]>

Serialize as a 64-byte keypair.

Returns
  • Some(bytes) if the public_key is present.
  • None if the public_key is absent (i.e. None).

Trait Implementations§

source§

impl Debug for KeypairBytes

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for KeypairBytes

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl EncodePrivateKey for KeypairBytes

Available on crate feature alloc only.
source§

fn to_pkcs8_der(&self) -> Result<SecretDocument>

Serialize a SecretDocument containing a PKCS#8-encoded private key.
source§

fn to_pkcs8_pem( &self, line_ending: LineEnding ) -> Result<Zeroizing<String>, Error>

Available on crate feature pem only.
Serialize this private key as PEM-encoded PKCS#8 with the given [LineEnding].
source§

fn write_pkcs8_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>

Available on crate feature std only.
Write ASN.1 DER-encoded PKCS#8 private key to the given path
source§

fn write_pkcs8_pem_file( &self, path: impl AsRef<Path>, line_ending: LineEnding ) -> Result<(), Error>

Available on crate features pem and std only.
Write ASN.1 DER-encoded PKCS#8 private key to the given path
source§

impl FromStr for KeypairBytes

Available on crate feature pem only.
§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(pem: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
source§

impl TryFrom<&[u8]> for KeypairBytes

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(der_bytes: &[u8]) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&KeypairBytes> for PublicKeyBytes

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(keypair: &KeypairBytes) -> Result<PublicKeyBytes>

Performs the conversion.
source§

impl TryFrom<KeypairBytes> for PublicKeyBytes

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(keypair: KeypairBytes) -> Result<PublicKeyBytes>

Performs the conversion.
source§

impl TryFrom<PrivateKeyInfo<'_>> for KeypairBytes

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(private_key: PrivateKeyInfo<'_>) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DecodePrivateKey for Twhere T: for<'a> TryFrom<PrivateKeyInfo<'a>, Error = Error>,

source§

fn from_pkcs8_der(bytes: &[u8]) -> Result<T, Error>

Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary format).
source§

fn from_pkcs8_pem(s: &str) -> Result<Self, Error>

Available on crate feature pem only.
Deserialize PKCS#8-encoded private key from PEM. Read more
source§

fn read_pkcs8_der_file(path: impl AsRef<Path>) -> Result<Self, Error>

Available on crate feature std only.
Load PKCS#8 private key from an ASN.1 DER-encoded file on the local filesystem (binary format).
source§

fn read_pkcs8_pem_file(path: impl AsRef<Path>) -> Result<Self, Error>

Available on crate features pem and std only.
Load PKCS#8 private key from a PEM-encoded file on the local filesystem.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.