[][src]Struct libp2p_secio::SecioKeyPair

pub struct SecioKeyPair { /* fields omitted */ }

Private and public keys of the local node.

Generating offline keys with OpenSSL

RSA

Generating the keys:

openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -outform DER -pubout -out public.der
openssl pkcs8 -in private.pem -topk8 -nocrypt -out private.pk8
rm private.pem      # optional

Loading the keys:

This example is not tested
let key_pair = SecioKeyPair::rsa_from_pkcs8(include_bytes!("private.pk8"),
                                               include_bytes!("public.der"));

Methods

impl SecioKeyPair[src]

pub fn rsa_from_pkcs8<P>(
    private: &[u8],
    public: P
) -> Result<SecioKeyPair, Box<dyn Error + Send + Sync>> where
    P: Into<Vec<u8>>, 
[src]

Builds a SecioKeyPair from a PKCS8 private key and public key.

pub fn ed25519_generated() -> Result<SecioKeyPair, Box<dyn Error + Send + Sync>>[src]

Generates a new Ed25519 key pair and uses it.

pub fn ed25519_raw_key(
    key: impl AsRef<[u8]>
) -> Result<SecioKeyPair, Box<dyn Error + Send + Sync>>
[src]

Builds a SecioKeyPair from a raw ed25519 32 bytes private key.

Returns an error if the slice doesn't have the correct length.

pub fn secp256k1_generated(
) -> Result<SecioKeyPair, Box<dyn Error + Send + Sync>>
[src]

Generates a new random sec256k1 key pair.

pub fn secp256k1_raw_key<K>(
    key: K
) -> Result<SecioKeyPair, Box<dyn Error + Send + Sync>> where
    K: AsRef<[u8]>, 
[src]

Builds a SecioKeyPair from a raw secp256k1 32 bytes private key.

pub fn secp256k1_from_der<K>(
    key: K
) -> Result<SecioKeyPair, Box<dyn Error + Send + Sync>> where
    K: AsRef<[u8]>, 
[src]

Builds a SecioKeyPair from a secp256k1 private key in DER format.

pub fn to_public_key(&self) -> PublicKey[src]

Returns the public key corresponding to this key pair.

pub fn to_peer_id(&self) -> PeerId[src]

Builds a PeerId corresponding to the public key of this key pair.

Trait Implementations

impl Clone for SecioKeyPair[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Same for T

type Output = T

Should always be Self

impl<T> Erased for T