Struct SshKey

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

Represents the public key provided by the remote host

Implementations§

Source§

impl SshKey

Source

pub fn get_public_key_hash( &self, hash_type: PublicKeyHashType, ) -> SshResult<Vec<u8>>

Returns the public key hash in the requested format. The hash is returned as binary bytes. Consider using get_public_key_hash_hexa to return it in a more human readable format.

Source

pub fn get_public_key_hash_hexa( &self, hash_type: PublicKeyHashType, ) -> SshResult<String>

Returns the public key hash in a human readable form

Examples found in repository?
examples/whoami.rs (line 7)
4fn verify_known_hosts(sess: &Session) -> SshResult<()> {
5    let key = sess
6        .get_server_public_key()?
7        .get_public_key_hash_hexa(PublicKeyHashType::Sha256)?;
8
9    match sess.is_known_server()? {
10        KnownHosts::Ok => Ok(()),
11        KnownHosts::NotFound | KnownHosts::Unknown => {
12            eprintln!("The server is not a known host. Do you trust the host key?");
13            eprintln!("Public key hash: {}", key);
14
15            let input = prompt_stdin("Enter yes to trust the key: ")?;
16            if input == "yes" {
17                sess.update_known_hosts_file()
18            } else {
19                Err(Error::Fatal("untrusted server".to_string()))
20            }
21        }
22        KnownHosts::Changed => {
23            eprintln!("The key for the server has changed. It is now:");
24            eprintln!("{}", key);
25            Err(Error::Fatal("host key changed".to_string()))
26        }
27        KnownHosts::Other => {
28            eprintln!("The host key for this server was not found, but another");
29            eprintln!("type of key exists. An attacker might change the default");
30            eprintln!("server key to confuse your client into thinking the key");
31            eprintln!("does not exist");
32            Err(Error::Fatal("host key has wrong type".to_string()))
33        }
34    }
35}
Source

pub fn from_privkey_base64( b64_key: &str, passphrase: Option<&str>, ) -> SshResult<SshKey>

Source

pub fn from_privkey_file( filename: &str, passphrase: Option<&str>, ) -> SshResult<SshKey>

Trait Implementations§

Source§

impl Drop for SshKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for SshKey

§

impl RefUnwindSafe for SshKey

§

impl !Send for SshKey

§

impl !Sync for SshKey

§

impl Unpin for SshKey

§

impl UnwindSafe for SshKey

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, 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, 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.