Struct makiko::host_file::File

source ·
pub struct File { /* private fields */ }
Expand description

Representation of an OpenSSH-compatible known_hosts file.

This file stores information about host keys. It is a list of entries, where each entry has a hostname and a public key. The hostname can be represented in plaintext (example.com), as a plaintext pattern (*.examp?e.com), as a list of such patterns (example.com,github.com) or in a hashed format that hides the hostname (|1|kRjF0OC...).

You can iterate over all entries using entries(), or you can use match_hostname_key()/match_host_port_key() to lookup the entries that either accept or revoke a given combination of host and key.

You can also append new entries to the file using append_entry(). In this way, it is possible to update the known_hosts file with new keys, without touching the previous entries (all previous lines will be preserved verbatim, including comments and invalid lines).

Implementations§

source§

impl File

source

pub fn decode(data: Bytes) -> Self

Parses a file in OpenSSH known_hosts format.

This function never fails: invalid lines are silently ignored.

source

pub fn new() -> Self

Creates a new empty File.

source

pub fn entries(&self) -> impl Iterator<Item = &Entry>

Iterates through all entries in the file.

Comments and invalid lines are not returned by this method.

source

pub fn match_hostname_key( &self, hostname: &str, pubkey: &Pubkey ) -> KeyMatch<'_>

Finds the match for the given hostname and key in this file.

See host_port_to_hostname() for the format of the hostname; you can use match_host_port_key() to match a (host, port) pair.

If you want more advanced processing, you can use entries() to list all entries and the Entry::matches_hostname() and Entry::pubkey() methods to match them to a hostname and key.

source

pub fn match_host_port_key( &self, host: &str, port: u16, pubkey: &Pubkey ) -> KeyMatch<'_>

Finds the match for the given host and port in this file.

Same as match_hostname_key(), but formats the host and port using host_port_to_hostname().

source

pub fn entry_builder() -> EntryBuilder

Creates an EntryBuilder, which can be used to add an entry (or a set of entries) to the file (see append_entry()).

source

pub fn append_entry(&mut self, builder: &EntryBuilder)

Appends all entries from the EntryBuilder to this file.

source

pub fn encode(&self) -> BytesMut

Encodes this file into an OpenSSH-compatible known_hosts file.

If the file was created using decode(), the original lines will be preserved verbatim, including comments and invalid lines. Entries added using append_entry() will be appended as new lines at the end of the file.

Trait Implementations§

source§

impl Clone for File

source§

fn clone(&self) -> File

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for File

source§

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

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

impl Default for File

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl UnwindSafe for File

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> 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V