pub struct ScramClient { /* private fields */ }Expand description
Client-side SCRAM-SHA-256 state machine. Holds the plaintext password and the derived keys for one authentication exchange. Construct a fresh instance per upstream connection.
Implementations§
Source§impl ScramClient
impl ScramClient
pub fn new(password: &str) -> Self
Sourcepub fn initial_response(&self) -> Vec<u8> ⓘ
pub fn initial_response(&self) -> Vec<u8> ⓘ
Build the SASLInitialResponse payload (mechanism name + client-first-message).
Sourcepub async fn handle_server_first(
&mut self,
data: &[u8],
) -> Result<Vec<u8>, AuthError>
pub async fn handle_server_first( &mut self, data: &[u8], ) -> Result<Vec<u8>, AuthError>
Process the server-first-message (from AuthenticationSASLContinue).
Returns the client-final-message bytes to send as SASLResponse.
This method is async because it offloads the PBKDF2 key
derivation to the tokio blocking thread pool. PostgreSQL 15+
defaults to 600_000 iterations (up from 4_096 in earlier
versions), which takes hundreds of milliseconds to hash —
running that synchronously on an async worker would starve
every other task on the same worker thread for the full
duration. VerifierCache::try_get_with additionally
coalesces concurrent auth requests, so a cache miss under
blocking PBKDF2 would freeze every pending authenticator
waiting on the shared fetch.