Skip to main content

KeyPair

Struct KeyPair 

Source
pub struct KeyPair { /* private fields */ }
Expand description

A moshpit key pair consisting of a private and public key.

Implementations§

Source§

impl KeyPair

Source

pub fn private_key(&self) -> &String

The encoded private key bytes.

Source

pub fn public_key(&self) -> &String

The encoded public key bytes.

Source

pub fn public_key_bytes(&self) -> &Vec<u8>

The public key bytes.

Source§

impl KeyPair

Source

pub fn default_key_path_ext( mode: KexMode, key_alg: &str, ) -> Result<(PathBuf, &'static str)>

Returns the default private key path and public key extension for use in key generation.

§Errors

If the home directory cannot be determined, an error is returned.

Source

pub fn generate_key_pair( passphrase_opt: Option<&String>, mode: KexMode, key_alg: &str, ) -> Result<Self>

Generates a new moshpit key pair, optionally protected by a passphrase.

The public key format is the following bytes encoded in base64:

<key algorithm length (kal)> (   4 bytes)
<key algorithm>              ( kal bytes)
<public key length (pbkl)>   (   4 bytes)
<public key>                 (pbkl bytes)
00000000  00 00 00 06 58 32 35 35  31 39 00 00 00 20 e7 62  |....X25519... .b|
00000010  70 bd fd 53 e7 23 ef 22  c5 c5 1b 82 01 d9 10 2b  |p..S.#.".......+|
00000020  88 7c ae 33 2b 72 f9 55  61 96 98 05 ed 14        |.|.3+r.Ua.....|

The private key format is the following bytes encoded in base64:

Unencrypted private key:

<magic header (moshpit-key-v1)> (  14 bytes)
<cipher length (cl)>            (   4 bytes)
<cipher>                        (  cl bytes)
<kdf length (kdl)>              (   4 bytes)
<kdf>                           ( kdl bytes)
<key algorithm length (kal)>    (   4 bytes)
<key algorithm>                 ( kal bytes)
<public key length (pbkl)>      (   4 bytes)
<public key>                    (pbkl bytes)
<private key length (pvkl)>     (   4 bytes)
<private key>                   (pvkl bytes)
00000000  6d 6f 73 68 70 69 74 2d  6b 65 79 2d 76 31 00 00  |moshpit-key-v1..|
00000010  00 04 6e 6f 6e 65 00 00  00 04 6e 6f 6e 65 00 00  |..none....none..|
00000020  00 06 58 32 35 35 31 39  00 00 00 20 3e 92 69 30  |..X25519... >.i0|
00000030  c1 b9 95 e3 09 ba b2 66  84 71 0c 1d 1d f7 c6 6b  |.......f.q.....k|
00000040  ed 49 6a 0d 66 f3 7e 92  76 1e 09 7d 00 00 00 20  |.Ij.f.~.v..}... |
00000050  0f 6f 52 ac 2f d5 13 07  64 6e 96 7c c8 de dd ec  |.oR./...dn.|....|
00000060  4f 03 4b af b9 81 77 00  85 27 a9 01 48 b6 d5 8e  |O.K...w..'..H...|

Encrypted private key:

<magic header (moshpit-key-v1)>       (  14 bytes)
<cipher length (cl)>                  (   4 bytes)
<cipher>                              (  cl bytes)
<kdf length (kdl)>                    (   4 bytes)
<kdf>                                 ( kdl bytes)
<key algorithm length (kal)>          (   4 bytes)
<key algorithm>                       ( kal bytes)
<public key length (pbkl)>            (   4 bytes)
<public key>                          (pbkl bytes)
<hkdf salt length (hsl)>              (   4 bytes)
<hkdf salt>                           ( hsl bytes)
<nonce length (nl)>                   (   4 bytes)
<nonce>                               (  nl bytes)
<encrypted private key length (epkl)> (   4 bytes)
<encrypted private key>               (epkl bytes)
00000000  6d 6f 73 68 70 69 74 2d  6b 65 79 2d 76 31 00 00  |moshpit-key-v1..|
00000010  00 0f 61 65 73 2d 32 35  36 2d 67 63 6d 2d 73 69  |..aes-256-gcm-si|
00000020  76 00 00 00 61 24 61 72  67 6f 6e 32 69 64 24 76  |v...a$argon2id$v|
00000030  3d 31 39 24 6d 3d 31 39  34 35 36 2c 74 3d 32 2c  |=19$m=19456,t=2,|
00000040  70 3d 31 24 72 56 53 6c  73 4b 6a 44 45 56 70 4a  |p=1$rVSlsKjDEVpJ|
00000050  7a 4c 6d 71 79 54 45 34  75 67 24 69 42 78 6c 50  |zLmqyTE4ug$iBxlP|
00000060  36 59 45 66 79 56 30 59  69 68 53 4a 6d 58 6e 31  |6YEfyV0YihSJmXn1|
00000070  63 34 55 63 6d 33 4e 50  4b 4a 7a 51 54 75 54 6d  |c4Ucm3NPKJzQTuTm|
00000080  75 57 58 64 50 77 00 00  00 06 58 32 35 35 31 39  |uWXdPw....X25519|
00000090  00 00 00 20 e7 62 70 bd  fd 53 e7 23 ef 22 c5 c5  |... .bp..S.#."..|
000000a0  1b 82 01 d9 10 2b 88 7c  ae 33 2b 72 f9 55 61 96  |.....+.|.3+r.Ua.|
000000b0  98 05 ed 14 00 00 00 40  6d 03 02 2f 5a a5 cf 07  |.......@m../Z...|
000000c0  96 ee b5 c9 37 28 bf e2  05 68 7d 06 f3 7d 9b dc  |....7(...h}..}..|
000000d0  40 46 64 b3 4a 9a f9 bf  b6 a8 3b b6 64 0a 70 82  |@Fd.J.....;.d.p.|
000000e0  b3 bd 40 1a 4b a0 98 49  3f 4b fe 9e 5d ab 46 f6  |..@.K..I?K..].F.|
000000f0  43 bd cc 5b 8d e1 ae b9  00 00 00 0c 26 84 7d 32  |C..[........&.}2|
00000100  4e 23 8b a3 01 98 f2 17  00 00 00 30 43 f4 a2 d6  |N#.........0C...|
00000110  e4 8a d5 50 ef e1 d2 7e  dd 71 17 f2 a7 e4 72 fa  |...P...~.q....r.|
00000120  08 bd 41 63 7e f1 3f a6  7b ac 91 ae 32 c1 c7 40  |..Ac~.?.{...2..@|
00000130  44 d7 c0 1c 2b 25 ff aa  d5 d2 01 e7              |D...+%......|
§Errors

If key generation or encryption fails, an error is returned.

Source

pub fn write_private_key<T>(&self, writer: &mut T) -> Result<()>
where T: Write,

Write the private key to the provided writer.

§Errors

If the hostname or username cannot be determined, an error is returned. If the write operation fails, an error is returned.

Source

pub fn write_public_key<T>(&self, writer: &mut T) -> Result<()>
where T: Write,

Write the public key to the provided writer.

§Errors

If the hostname or username cannot be determined, an error is returned. If the write operation fails, an error is returned.

Source

pub fn fingerprint(&self) -> Result<String>

Get the public key fingerprint for this key pair.

§Errors

If the hostname or username cannot be determined, an error is returned.

Source

pub fn randomart(&self) -> String

Get the randomart image for this key pair.

Trait Implementations§

Source§

impl Debug for KeyPair

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more