pub trait Kex: Sized {
type Hash: Digest;
type Init: Decode<Error = Error> + Encode;
type Reply: Decode<Error = Error> + Encode;
type Secret: AsRef<[u8]> + Encode;
type Error: Error;
const NAME: &'static str;
// Required methods
fn start<R: CryptoRng + ?Sized>(
rng: &mut R,
) -> Result<(Self, Self::Init), Self::Error>;
fn respond<R: CryptoRng + ?Sized>(
rng: &mut R,
init: &Self::Init,
) -> Result<(Self::Reply, Self::Secret), Self::Error>;
fn finish(self, reply: &Self::Reply) -> Result<Self::Secret, Self::Error>;
}Expand description
An SSH key exchange with one client initiation and one server reply.
The method-specific fields must encode exactly as received. Implementations that accept multiple representations of a public key must retain the original encoding for the hash.
Implement this trait on the client’s ephemeral state. The server calls
respond to generate its reply and shared secret in one step.
The transport handles method negotiation, packet framing, and host authentication.
DH group exchange (RFC 4419) requires additional negotiation and transcript fields.
Required Associated Constants§
Required Associated Types§
Sourcetype Init: Decode<Error = Error> + Encode
type Init: Decode<Error = Error> + Encode
Client’s method-specific field, including its SSH wire framing.
Sourcetype Reply: Decode<Error = Error> + Encode
type Reply: Decode<Error = Error> + Encode
Server’s method-specific field, including its SSH wire framing.
Required Methods§
Sourcefn start<R: CryptoRng + ?Sized>(
rng: &mut R,
) -> Result<(Self, Self::Init), Self::Error>
fn start<R: CryptoRng + ?Sized>( rng: &mut R, ) -> Result<(Self, Self::Init), Self::Error>
Generate a fresh client state and the public field to send.
§Errors
Returns a method-specific error if key generation fails.
Sourcefn respond<R: CryptoRng + ?Sized>(
rng: &mut R,
init: &Self::Init,
) -> Result<(Self::Reply, Self::Secret), Self::Error>
fn respond<R: CryptoRng + ?Sized>( rng: &mut R, init: &Self::Init, ) -> Result<(Self::Reply, Self::Secret), Self::Error>
Process the client’s public field and generate the server’s reply and shared secret.
§Errors
Returns a method-specific error if key generation or peer key validation fails.
Sourcefn finish(self, reply: &Self::Reply) -> Result<Self::Secret, Self::Error>
fn finish(self, reply: &Self::Reply) -> Result<Self::Secret, Self::Error>
Consume the client state and derive the shared secret from the server’s public field.
The client authenticates the server by checking its host key and signature over H.
§Errors
Returns a method-specific error if key agreement fails.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".