ScramClient

Struct ScramClient 

Source
pub struct ScramClient {
    pub client_nonce_b64: String,
    pub client_first_bare: String,
    pub client_first: String,
}
Expand description

SCRAM-SHA-256 client state.

Holds the client nonce and first message needed for the authentication exchange.

Fields§

§client_nonce_b64: String

Base64-encoded client nonce (18 random bytes)

§client_first_bare: String

Client-first-message-bare (without channel binding prefix)

§client_first: String

Complete client-first-message to send to server

Implementations§

Source§

impl ScramClient

Source

pub fn new(username: &str) -> ScramClient

Create a new SCRAM client with a random nonce.

§Arguments
  • username - PostgreSQL username (will be SASL-escaped)
Source

pub fn parse_server_first(server_first: &str) -> Result<(String, String, u32)>

Parse server-first-message.

Extracts:

  • r: Combined nonce (client nonce + server nonce)
  • s: Base64-encoded salt
  • i: Iteration count
§Errors

Returns error if any required field is missing or malformed.

Source

pub fn client_final( &self, password: &str, server_first: &str, ) -> Result<(String, String, Vec<u8>)>

Compute client-final-message.

§Arguments
  • password - User’s password
  • server_first - Server-first-message received from server
§Returns

Tuple of:

  • client_final: Message to send to server
  • auth_message: Full auth message (needed for server verification)
  • salted_password: Derived key (needed for server verification)
§Errors
  • Nonce doesn’t start with client nonce (possible MITM)
  • Invalid base64 in salt
Source

pub fn verify_server_final( server_final: &str, salted_password: &[u8], auth_message: &str, ) -> Result<()>

Verify server-final-message.

This provides mutual authentication - ensures we’re talking to a server that knows the password, not an impostor.

§Arguments
  • server_final - Server-final-message received
  • salted_password - From client_final() return value
  • auth_message - From client_final() return value
§Errors
  • Missing server signature
  • Invalid base64
  • Signature mismatch (server doesn’t know password)

Trait Implementations§

Source§

impl Clone for ScramClient

Source§

fn clone(&self) -> ScramClient

Returns a duplicate 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 ScramClient

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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