Behavior

Trait Behavior 

Source
pub trait Behavior {
    type Stream: Read + Write;
    type Random: CryptoRng + Rng;
    type User: Clone;
    type Command: Clone;

    // Required methods
    fn stream(&mut self) -> &mut Self::Stream;
    fn random(&mut self) -> &mut Self::Random;
    fn host_secret_key(&self) -> &SecretKey;
    fn allow_user(
        &mut self,
        username: &str,
        auth_method: &AuthMethod,
    ) -> Option<Self::User>;
    fn parse_command(&mut self, command: &str) -> Self::Command;

    // Provided methods
    fn server_id(&self) -> &'static str { ... }
    fn allow_shell(&self) -> bool { ... }
}
Expand description

Description of aspects of the server’s behavior.

Required Associated Types§

Source

type Stream: Read + Write

The underlying stream type.

Source

type Random: CryptoRng + Rng

The underlying random type.

Source

type User: Clone

Type representing an authenticated user.

Source

type Command: Clone

Type representing a user-supplied command.

Required Methods§

Source

fn stream(&mut self) -> &mut Self::Stream

The underlying stream type to be used.

Source

fn random(&mut self) -> &mut Self::Random

The underlying random type to be used.

Source

fn host_secret_key(&self) -> &SecretKey

The secret key advertised by the server.

Source

fn allow_user( &mut self, username: &str, auth_method: &AuthMethod, ) -> Option<Self::User>

Allow a given user to authenticate with a given auth method.

Returns None if the user’s auth method is not acceptable (e.g. public key does not match a whitelist), otherwise returns a type representing a user identity.

This may be called more than once if the client uses probe requests.

Source

fn parse_command(&mut self, command: &str) -> Self::Command

Parse a user-supplied command string into a command.

It is not permitted to “fail” to parse a command, instead just represent invalid commands as a “print usage” command variant so as to handle all possible inputs.

Provided Methods§

Source

fn server_id(&self) -> &'static str

The server’s identification string.

This will be sent to the client during the initial version handshake. It must comply with RFC4253 section 4.2 except it should not contain the final CR LF.

Source

fn allow_shell(&self) -> bool

Whether to allow shell channel requests.

Note that if this returns true, the server code must be prepared to handle shell requests by accepting interactive input in ways similar to a real shell process.

Implementors§